YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_promise.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace yaclib {
6
7template <typename V, typename E>
9 static_assert(Check<V>(), "V should be valid");
10 static_assert(Check<E>(), "E should be valid");
11 static_assert(!std::is_same_v<V, E>, "Future cannot be instantiated with same V and E, because it's ambiguous");
12 static_assert(std::is_copy_constructible_v<Result<V, E>>, "Result should be copyable");
13
14 public:
16
19
22
24 return _core != nullptr;
25 }
26
27 template <typename... Args>
28 void Set(Args&&... args) && {
30 if constexpr (sizeof...(Args) == 0) {
31 _core->Set(std::in_place);
32 } else {
33 _core->Set(std::forward<Args>(args)...);
34 }
35 _core = nullptr;
36 }
37
39 if (Valid()) {
40 std::move(*this).Set(StopTag{});
41 }
42 }
43
44 /**
45 * Part of unsafe but internal API
46 */
48 }
49
50 private:
52};
53
54} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
void Set(Args &&... args) &&
bool Valid() const &noexcept
SharedPromise(detail::SharedCorePtr< V, E > core) noexcept
Part of unsafe but internal API.
SharedPromise() noexcept=default
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25