YOrch 1.0.0
Loading...
Searching...
No Matches
direct_out.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4#include <utility>
5
6#include "../detail/slots/slot_view.hpp"
7#include "../detail/slots/typed_slot.hpp"
8#include "../result.hpp"
9
10namespace yorch {
11
27template <typename T>
28struct direct_out {
29 static_assert(!std::is_reference_v<T>,
30 "yorch::direct_out<T> does not support reference types; direct-output payloads must be owned values");
31 static_assert(!std::is_void_v<T>,
32 "yorch::direct_out<T> requires a non-void payload type");
33
34 constexpr explicit direct_out(
36 : slot_(slot) {}
37
41 constexpr explicit direct_out(detail::slot_view<T> slot) noexcept
42 : slot_(slot) {}
43
44 template <typename... Args>
45 constexpr T& emplace(Args&&... args)
46 noexcept(noexcept(slot_.emplace(std::forward<Args>(args)...))) {
47 return slot_.emplace(std::forward<Args>(args)...);
48 }
49
50 template <typename... Args>
51 [[nodiscard]] constexpr step_result success(Args&&... args)
52 noexcept(noexcept(emplace(std::forward<Args>(args)...))) {
53 emplace(std::forward<Args>(args)...);
54 return step_result::success();
55 }
56
57 constexpr void destroy() noexcept {
58 slot_.destroy();
59 }
60
61 [[nodiscard]] constexpr bool has_value() const noexcept {
62 return slot_.has_value();
63 }
64
65private:
66 detail::slot_view<T> slot_ {};
67};
68
69} // namespace yorch
Non-owning typed access view over a slot-like storage object.
Definition slot_view.hpp:24
Output sink passed to direct-output tasks.
constexpr void destroy() noexcept
constexpr step_result success(Args &&... args) noexcept(noexcept(emplace(std::forward< Args >(args)...)))
constexpr direct_out(detail::slot_view< T > slot) noexcept
Binds the sink to an already-created typed slot view.
constexpr bool has_value() const noexcept
constexpr T & emplace(Args &&... args) noexcept(noexcept(slot_.emplace(std::forward< Args >(args)...)))
constexpr direct_out(detail::typed_slot< T, detail::slot_logical_policy::maybe_payload > &slot) noexcept
Represents the basic outcome of a task step.
Definition result.hpp:42
static constexpr step_result success() noexcept
Creates a successful result.
Definition result.hpp:46