-/** Fulfill a promise by executing a given code */
-template<class R, class F>
-void fulfillPromise(std::promise<R>& promise, F code)
+/** A value or an exception (or nothing)
+ *
+ * This is similar to `optional<expected<T>>`` but it with a Future/Promise
+ * like API.
+ *
+ * Also the name is not so great.
+ **/
+template<class T>
+class Result {
+public:
+ bool is_valid() const
+ {
+ return value_.which() > 0;
+ }
+ void set_exception(std::exception_ptr e)
+ {
+ value_ = std::move(e);
+ }
+ void set_value(T&& value)
+ {
+ value_ = std::move(value);
+ }
+ void set_value(T const& value)
+ {
+ value_ = value;
+ }
+
+ /** Extract the value from the future
+ *
+ * After this, the value is invalid.
+ **/
+ T get()
+ {
+ switch (value_.which()) {
+ case 1: {
+ T value = std::move(boost::get<T>(value_));
+ value_ = boost::blank();
+ return value;
+ }
+ case 2: {
+ std::exception_ptr exception = std::move(boost::get<std::exception_ptr>(value_));
+ value_ = boost::blank();
+ std::rethrow_exception(std::move(exception));
+ break;
+ }
+ default:
+ throw std::future_error(std::future_errc::no_state);
+ }
+ }
+private:
+ boost::variant<boost::blank, T, std::exception_ptr> value_;
+};
+
+template<>
+class Result<void> : public Result<std::nullptr_t>