@@ -133,32 +133,31 @@ constexpr size_t variant_index()
133133// / expected<T> is either a T or the exception preventing its creation.
134134template <class T >
135135class expected {
136+ std::variant<std::exception_ptr, T> val_;
137+
136138public:
137139 template <class F , class ... Args>
138140 static expected result_of (F&& f, Args&&... args) noexcept
139141 {
140142 expected res;
141143 try {
142- res.state_ =
144+ res.val_ =
143145 std::invoke (std::forward<F>(f), std::forward<Args>(args)...);
144146 }
145- catch (const std::exception& ) {
146- res.state_ = std::current_exception ();
147+ catch (... ) {
148+ res.val_ = std::current_exception ();
147149 }
148150 return res;
149151 }
150152
151- T get ()
153+ T get () &&
152154 {
153- return std::visit (overloaded{[](T& val) -> T { return std::move (val); },
154- [](std::exception_ptr& e) -> T {
155- std::rethrow_exception (std::move (e));
156- }},
157- state_ );
155+ return std::visit (
156+ overloaded {
157+ [](std::exception_ptr e) -> T { std::rethrow_exception (e); },
158+ [](T&& val) -> T { return std::move (val); }},
159+ std::move (val_) );
158160 }
159-
160- private:
161- std::variant<std::exception_ptr, T> state_;
162161};
163162
164163// / Joins 'items' by adding user defined separator.
@@ -240,6 +239,11 @@ streamable(T) -> streamable<T>;
240239// / @see https://en.cppreference.com/w/cpp/named_req/TimedLockable
241240template <class T , class Hash = std::hash<T>, class Equal = std::equal_to<T>>
242241class timed_lockable {
242+ T val_;
243+ inline static std::mutex guard_;
244+ inline static std::condition_variable notifier_;
245+ inline static std::unordered_set<T, Hash, Equal> locked_;
246+
243247public:
244248 explicit timed_lockable (const T& val) : val_{val} {}
245249
@@ -260,12 +264,6 @@ class timed_lockable {
260264 }
261265 notifier_.notify_all ();
262266 }
263-
264- private:
265- T val_;
266- inline static std::mutex guard_;
267- inline static std::condition_variable notifier_;
268- inline static std::unordered_set<T, Hash, Equal> locked_;
269267};
270268
271269} // namespace bark
0 commit comments