aboutsummaryrefslogtreecommitdiff
path: root/src/result.hpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 04:50:51 -0400
committerGitHub <noreply@github.com>2018-08-25 04:50:51 -0400
commit4003cd4747019d79ff50aaa22415d2d3dfc15cf4 (patch)
tree1f77690a5fb7ccbef75bcab9c8c1e008ef3c5068 /src/result.hpp
parentbf1f91595d4d3b5911632c671ef16e44d70dc9a6 (diff)
parent815950996dcc92ac6ac285f2005dbac51b9cb6f8 (diff)
downloadzig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.tar.gz
zig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.zip
Merge pull request #1406 from ziglang/macos-stack-traces
MacOS stack traces closes #1365
Diffstat (limited to 'src/result.hpp')
-rw-r--r--src/result.hpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/result.hpp b/src/result.hpp
new file mode 100644
index 0000000000..6c9f35c0b6
--- /dev/null
+++ b/src/result.hpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Andrew Kelley
+ *
+ * This file is part of zig, which is MIT licensed.
+ * See http://opensource.org/licenses/MIT
+ */
+
+#ifndef ZIG_RESULT_HPP
+#define ZIG_RESULT_HPP
+
+#include "error.hpp"
+
+#include <assert.h>
+
+static inline void assertNoError(Error err) {
+ assert(err == ErrorNone);
+}
+
+template<typename T>
+struct Result {
+ T data;
+ Error err;
+
+ Result(T x) : data(x), err(ErrorNone) {}
+
+ Result(Error err) : err(err) {
+ assert(err != ErrorNone);
+ }
+
+ T unwrap() {
+ assert(err == ErrorNone);
+ return data;
+ }
+};
+
+#endif