YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
all_tuple.hpp
Go to the documentation of this file.
1#pragma once
2
4
10
11namespace yaclib::when {
12
13template <FailPolicy F, typename OutputValue, typename OutputError, typename InputCore>
14struct AllTuple {
15 static_assert(F != FailPolicy::LastFail, "LastFail policy is not supported by AllTuple");
16};
17
18template <typename OutputValue, typename OutputError, typename InputCore>
19struct AllTuple<FailPolicy::None, OutputValue, OutputError, InputCore> {
21
22 static constexpr ConsumePolicy kConsumePolicy = ConsumePolicy::Static;
23 static constexpr CorePolicy kCorePolicy = CorePolicy::Managed;
24
25 AllTuple(std::size_t count, PromiseType p) : _p{std::move(p)} {
26 }
27
28 template <std::size_t Index, typename Result>
30 std::get<Index>(_tuple) = std::forward<Result>(result);
31 }
32
34 std::move(_p).Set(std::move(_tuple));
35 }
36
37 private:
38 OutputValue _tuple;
39 PromiseType _p;
40};
41
42template <typename OutputValue, typename OutputError, typename InputCore>
45
46 static constexpr ConsumePolicy kConsumePolicy = ConsumePolicy::Static;
47 static constexpr CorePolicy kCorePolicy = CorePolicy::Managed;
48
49 AllTuple(std::size_t count, PromiseType p) : _p{std::move(p)} {
50 }
51
52 template <std::size_t Index, typename Result>
54 if (!result && !_done.load(std::memory_order_relaxed) && !_done.exchange(true, std::memory_order_acq_rel)) {
55 if (result.State() == ResultState::Error) {
56 std::move(_p).Set(std::forward<Result>(result).Error());
57 } else {
58 std::move(_p).Set(std::forward<Result>(result).Exception());
59 }
60 } else {
61 std::get<Index>(_tuple) = std::forward<Result>(result).Value();
62 }
63 }
64
66 if (_p.Valid()) {
67 std::move(_p).Set(std::move(_tuple));
68 }
69 }
70
71 private:
72 yaclib_std::atomic_bool _done = false;
73 OutputValue _tuple;
74 PromiseType _p;
75};
76
77} // namespace yaclib::when
Encapsulated return value from caller.
Definition result.hpp:90
atomic< bool > atomic_bool
Definition atomic.hpp:41
FailPolicy
This Policy describe how algorithm interpret if Future will be fulfilled by fail (exception or error)
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25