+#ifndef maybe_h
+#define maybe_h
+
+#include <cassert>
+
+template <class T> struct maybe {
+ bool isJust = false;
+ union { T t; };
+ maybe() {}
+ maybe(const maybe & other) {
+ *this = other;
+ }
+ ~maybe() {
+ if (isJust)
+ t.~T();
+ }
+ const maybe & operator =(const maybe & other) {
+ if (isJust) t.~T();
+ isJust = other.isJust;
+ if(isJust) new(&t) T(other.t);
+ return *this;
+ }
+ operator T &() { assert(isJust); return t; }
+ operator bool() { return isJust; }
+};
+
+template <class T>
+static inline maybe<T> nothing() {return maybe<T>();}
+template <class T>
+static inline maybe<T> just(const T & t_) { maybe<T> m; m.isJust = true; new(&m.t) T(t_); return m; }
+
+#endif