YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
make.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace yaclib {
7namespace detail {
8
9template <typename V, typename E>
10class ReadyCore : public ResultCore<V, E> {
11 public:
12 template <typename... Args>
13 ReadyCore(Args&&... args) noexcept(std::is_nothrow_constructible_v<Result<V, E>, Args&&...>) {
14 this->Store(std::forward<Args>(args)...);
15 }
16
18 Loop(this, this->template SetResult<false>());
19 }
20
22 this->_result.~Result<V, E>();
23 this->Store(StopTag{});
24 Call();
25 }
26
27 [[nodiscard]] InlineCore* Here(InlineCore& /*caller*/) noexcept final {
28 return this->template SetResult<false>();
29 }
30#if YACLIB_SYMMETRIC_TRANSFER != 0
31 [[nodiscard]] yaclib_std::coroutine_handle<> Next(InlineCore& /*caller*/) noexcept final {
32 return this->template SetResult<true>();
33 }
34#endif
35};
36
37} // namespace detail
38
39/**
40 * TODO(MBkkt) add description
41 */
42template <typename V = Unit, typename E = StopError, typename... Args>
43/*Task*/ auto MakeTask(Args&&... args) {
44 if constexpr (sizeof...(Args) == 0) {
45 using T = std::conditional_t<std::is_same_v<V, Unit>, void, V>;
47 } else if constexpr (std::is_same_v<V, Unit>) {
48 using T0 = std::decay_t<head_t<Args&&...>>;
49 using T = std::conditional_t<std::is_same_v<T0, Unit>, void, T0>;
50 return Task{
51 detail::ResultCorePtr<T, E>{MakeUnique<detail::ReadyCore<T, E>>(std::in_place, std::forward<Args>(args)...)}};
52 } else {
54 }
55}
56
57} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
Provides a mechanism to schedule the some async operations TODO(MBkkt) add description.
Definition task.hpp:25
void Call() noexcept final
Definition make.hpp:17
ReadyCore(Args &&... args) noexcept(std::is_nothrow_constructible_v< Result< V, E >, Args &&... >)
Definition make.hpp:13
InlineCore * Here(InlineCore &) noexcept final
Definition make.hpp:27
void Drop() noexcept final
Definition make.hpp:21
void Store(Args &&... args) noexcept(std::is_nothrow_constructible_v< Result< V, E >, Args &&... >)
YACLIB_INLINE void Loop(InlineCore *prev, InlineCore *curr) noexcept
Definition base_core.hpp:69
typename detail::Head< Args... >::Type head_t
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
auto MakeTask(Args &&... args)
TODO(MBkkt) add description.
Definition make.hpp:43