summaryrefslogtreecommitdiffhomepage
path: root/CompilerKit/StdKit/ErrorOr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'CompilerKit/StdKit/ErrorOr.hpp')
-rw-r--r--CompilerKit/StdKit/ErrorOr.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/CompilerKit/StdKit/ErrorOr.hpp b/CompilerKit/StdKit/ErrorOr.hpp
new file mode 100644
index 0000000..c2457df
--- /dev/null
+++ b/CompilerKit/StdKit/ErrorOr.hpp
@@ -0,0 +1,58 @@
+/*
+ * ========================================================
+ *
+ * CompilerKit
+ * Copyright Western Company, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <CompilerKit/Defines.hpp>
+#include <CompilerKit/StdKit/Ref.hpp>
+
+namespace CompilerKit
+{
+using ErrorT = UInt32;
+
+template <typename T>
+class ErrorOr final
+{
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
+
+ public:
+ explicit ErrorOr(Int32 err)
+ : mId(err)
+ {}
+
+ explicit ErrorOr(nullPtr Null)
+ {}
+
+ explicit ErrorOr(T Class)
+ : mRef(Class)
+ {}
+
+ ErrorOr &operator=(const ErrorOr &) = default;
+ ErrorOr(const ErrorOr &) = default;
+
+ Ref<T> Leak()
+ {
+ return mRef;
+ }
+
+ operator bool()
+ {
+ return mRef;
+ }
+
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+};
+
+using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace CompilerKit