YOrch 1.0.0
Loading...
Searching...
No Matches
erased_slot.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "policy.hpp"
6
7namespace yorch::detail {
8
9template <std::size_t Size, std::size_t Align, slot_physical_policy Policy>
11
12template <std::size_t Size, std::size_t Align>
15
16 [[nodiscard]] constexpr std::byte* raw_storage() noexcept {
17 return storage_;
18 }
19
20 [[nodiscard]] constexpr const std::byte* raw_storage() const noexcept {
21 return storage_;
22 }
23
24 [[nodiscard]] constexpr bool* engaged_ptr() noexcept {
25 return &engaged_;
26 }
27
28 [[nodiscard]] constexpr const bool* engaged_ptr() const noexcept {
29 return &engaged_;
30 }
31
32 [[nodiscard]] constexpr std::size_t* owner_node_ptr() noexcept {
33 return &owner_node_;
34 }
35
36 [[nodiscard]] constexpr const std::size_t* owner_node_ptr() const noexcept {
37 return &owner_node_;
38 }
39
40private:
41 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
42 alignas(Align) std::byte storage_[Size] {};
43 bool engaged_ = false;
44 std::size_t owner_node_ = no_physical_slot;
45};
46
47template <std::size_t Size, std::size_t Align>
49 static constexpr slot_physical_policy physical_policy = slot_physical_policy::must_payload;
50
51 [[nodiscard]] constexpr std::byte* raw_storage() noexcept {
52 return storage_;
53 }
54
55 [[nodiscard]] constexpr const std::byte* raw_storage() const noexcept {
56 return storage_;
57 }
58
59 [[nodiscard]] static constexpr bool* engaged_ptr() noexcept {
60 return nullptr;
61 }
62
63 [[nodiscard]] constexpr std::size_t* owner_node_ptr() noexcept {
64 return &owner_node_;
65 }
66
67 [[nodiscard]] constexpr const std::size_t* owner_node_ptr() const noexcept {
68 return &owner_node_;
69 }
70
71private:
72 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
73 alignas(Align) std::byte storage_[Size] {};
74 std::size_t owner_node_ = no_physical_slot;
75};
76
77} // namespace yorch::detail
constexpr std::size_t no_physical_slot
Sentinel physical slot index meaning "this node has no storage".
Definition policy.hpp:59
slot_physical_policy
Storage-level policy for a physical slot after layout selection.
Definition policy.hpp:32
constexpr bool is_adapter_descriptor_v
Definition adapters.hpp:63