YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
unique_core.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <type_traits>
6
7namespace yaclib::detail {
8
9template <typename V, typename E>
10class UniqueCore : public ResultCore<V, E> {
11 using ResultCore<V, E>::ResultCore;
12
13 public:
14 [[nodiscard]] InlineCore* Here(InlineCore& caller) noexcept override {
16 }
17
18#if YACLIB_SYMMETRIC_TRANSFER != 0
19 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& caller) noexcept override {
21 }
22#endif
23
25 if constexpr (std::is_move_constructible_v<Result<V, E>>) {
26 auto result = std::move(this->Get());
27 this->DecRef();
28 return result;
29 } else {
31 return {};
32 }
33 }
34
38
40 return BaseCore::SetCallbackImpl<false>(callback);
41 }
42
43 // Sometimes we know it will be last callback in cycle, so we want call it right now, instead of SetInline
44 void CallInline(InlineCore& callback) noexcept {
45 if (!SetCallback(callback)) {
46 auto* next = callback.Here(*this);
47 YACLIB_ASSERT(next == nullptr);
48 }
49 }
50
51 template <bool SymmetricTransfer>
53 return BaseCore::SetInlineImpl<SymmetricTransfer, false>(callback);
54 }
55
56 template <bool SymmetricTransfer>
58 return BaseCore::SetResultImpl<SymmetricTransfer, false>();
59 }
60};
61
62extern template class UniqueCore<void, StopError>;
63
64template <typename V, typename E>
66
67} // namespace yaclib::detail
virtual void DecRef() noexcept
Decrements reference counter.
Definition ref.hpp:23
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
Definition result.hpp:90
void StoreCallbackImpl(InlineCore &callback) noexcept
Definition base_core.hpp:53
Result< V, E > & Get() noexcept
InlineCore * Here(InlineCore &caller) noexcept override
Transfer< SymmetricTransfer > SetResult() noexcept
Result< V, E > Retire() final
void StoreCallback(InlineCore &callback) noexcept
void CallInline(InlineCore &callback) noexcept
Transfer< SymmetricTransfer > SetInline(InlineCore &callback) noexcept
bool SetCallback(InlineCore &callback) noexcept
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
#define YACLIB_PURE_VIRTUAL()
Definition log.hpp:86
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25