YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
result_core.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <utility>
8
9namespace yaclib::detail {
10
11struct Callback {
12 IRef* caller = nullptr;
13 char unwrapping = 0;
14};
15
16template <typename V, typename E>
17class ResultCore : public BaseCore {
18 template <bool SymmetricTransfer>
19 [[nodiscard]] YACLIB_INLINE auto Impl(InlineCore& /*caller*/) noexcept {
22 }
23
24 public:
25 [[nodiscard]] InlineCore* Here(InlineCore& caller) noexcept override {
26 return Impl<false>(caller);
27 }
28#if YACLIB_SYMMETRIC_TRANSFER != 0
29 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& caller) noexcept override {
30 return Impl<true>(caller);
31 }
32#endif
33
36
37 template <typename... Args>
38 explicit ResultCore(Args&&... args) noexcept(std::is_nothrow_constructible_v<Result<V, E>, Args&&...>)
39 : BaseCore{kResult}, _result{std::forward<Args>(args)...} {
40 }
41
42 ~ResultCore() noexcept override {
43 _result.~Result<V, E>();
44 }
45
46 template <typename... Args>
47 void Store(Args&&... args) noexcept(std::is_nothrow_constructible_v<Result<V, E>, Args&&...>) {
48 new (&_result) Result<V, E>{std::forward<Args>(args)...};
49 }
50
52 return _result;
53 }
54
55 union {
58 };
59};
60
61extern template class ResultCore<void, StopError>;
62
63template <typename V, typename E>
65
66} // namespace yaclib::detail
Reference counting interface.
Definition ref.hpp:8
A intrusive pointer to objects with an embedded reference count.
Encapsulated return value from caller.
Definition result.hpp:90
~ResultCore() noexcept override
ResultCore(Args &&... args) noexcept(std::is_nothrow_constructible_v< Result< V, E >, Args &&... >)
Result< V, E > & Get() noexcept
void Store(Args &&... args) noexcept(std::is_nothrow_constructible_v< Result< V, E >, Args &&... >)
InlineCore * Here(InlineCore &caller) noexcept override
#define YACLIB_PURE_VIRTUAL()
Definition log.hpp:86
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25