YOrch 1.0.0
Loading...
Searching...
No Matches
result.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <type_traits>
5#include <utility>
6
7#include "../../assert.hpp"
8#include "../../result.hpp"
9
10namespace yorch::detail {
11
23template <typename R>
24[[nodiscard]] constexpr step_result normalize_task_result(R&& r) { // NOLINT(readability-identifier-length)
25 using raw_t = std::remove_cvref_t<R>;
26
27 if constexpr (std::is_same_v<raw_t, step_result>) {
28 return std::forward<R>(r);
29 } else if constexpr (is_task_result_v<raw_t>) {
30 return std::forward<R>(r).step;
31 } else {
32 static_cast<void>(r);
33 return step_result::success();
34 }
35}
36
37template <typename R>
38[[nodiscard]] constexpr step_result extract_step_result(R&& r) { // NOLINT(readability-identifier-length)
39 return normalize_task_result(std::forward<R>(r));
40}
41
68template <std::size_t I, typename Slots, typename Raw>
69[[nodiscard]] constexpr bool store_node_output(Slots& slots, Raw& raw) {
70 using raw_t = std::remove_cvref_t<Raw>;
71
72 if constexpr (std::is_void_v<raw_t> ||
73 std::is_same_v<raw_t, step_result>) {
74 static_cast<void>(slots);
75 static_cast<void>(raw);
76 return false;
77 } else if constexpr (is_task_result_v<raw_t>) {
78 if (raw.step.ok()) {
79 YORCH_ASSERT(raw.has_value() &&
80 "Successful task_result<T> must carry a payload before slot storage");
81 slots.template emplace<I>(std::move(raw).value());
82 return true;
83 }
84
85 return false;
86 } else {
87 slots.template emplace<I>(std::move(raw));
88 return true;
89 }
90}
91
92template <typename Slots, std::size_t I>
95 bool armed = false;
96
99
104
105 constexpr void arm() noexcept {
106 armed = true;
107 }
108
110 if (armed) {
111 slots.template destroy<I>();
112 }
113 }
114};
115
116template <std::size_t I, typename Slots>
118 if (step.ok()) {
119 YORCH_ASSERT(slots.template has_value<I>() &&
120 "Direct-output tasks returning success must construct their payload");
121 } else {
122 slots.template destroy<I>();
123 }
124
125 return step;
126}
127
128} // namespace yorch::detail
#define YORCH_ASSERT(condition)
Definition assert.hpp:10
constexpr step_result extract_step_result(R &&r)
Definition result.hpp:38
constexpr step_result finalize_direct_output_step(Slots &slots, step_result step)
Definition result.hpp:117
constexpr bool store_node_output(Slots &slots, Raw &raw)
Materializes the payload portion of a node's raw task return into the node's compiled slot,...
Definition result.hpp:69
constexpr step_result normalize_task_result(R &&r)
Normalizes a raw task return into scheduler-facing step_result.
Definition result.hpp:24
constexpr bool is_adapter_descriptor_v
Definition adapters.hpp:63
constexpr auto value(T &&v) -> value_t< std::remove_cvref_t< T > >
Wraps a value as an owning spec.
Definition specs.hpp:179
constexpr node_slot_guard(Slots &stored_slots) noexcept
Definition result.hpp:97
node_slot_guard & operator=(node_slot_guard &&)=delete
constexpr void arm() noexcept
Definition result.hpp:105
node_slot_guard(const node_slot_guard &)=delete
node_slot_guard & operator=(const node_slot_guard &)=delete
node_slot_guard(node_slot_guard &&)=delete
Represents the basic outcome of a task step.
Definition result.hpp:42
constexpr bool ok() const noexcept
Returns whether the status is success.
Definition result.hpp:71
static constexpr step_result success() noexcept
Creates a successful result.
Definition result.hpp:46