kokkos-execution 0.0.1
Loading...
Searching...
No Matches
optional_storage.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_OPTIONAL_STORAGE_HPP
2#define KOKKOS_EXECUTION_IMPL_OPTIONAL_STORAGE_HPP
3
5
6#include "Kokkos_Core.hpp"
7
9
20template <typename T>
22 public:
23 constexpr OptionalStorage() noexcept = default;
24
25 constexpr ~OptionalStorage() {
26 if (m_has_value) {
27 m_storage.__destroy();
28 }
29 }
30
35
36 template <typename... Args>
37 constexpr auto emplace(Args&&... args) noexcept(std::is_nothrow_constructible_v<T, Args...>) -> T& {
38 KOKKOS_ASSERT(!m_has_value);
39 auto& ref = m_storage.__construct(std::forward<Args>(args)...);
40 m_has_value = true;
41 return ref;
42 }
43
44 template <typename Func, typename... Args>
45 constexpr auto emplace_from(Func&& func, Args&&... args)
46 noexcept(noexcept(T{std::forward<Func>(func)(std::forward<Args>(args)...)})) -> T& {
47 KOKKOS_ASSERT(!m_has_value);
48 auto& ref = m_storage.__construct_from(std::forward<Func>(func), std::forward<Args>(args)...);
49 m_has_value = true;
50 return ref;
51 }
52
53 constexpr void reset() noexcept {
54 KOKKOS_ASSERT(m_has_value);
55 m_storage.__destroy();
56 m_has_value = false;
57 }
58
59 constexpr auto get() & noexcept -> T& {
60 KOKKOS_ASSERT(m_has_value);
61 return m_storage.__get();
62 }
63
64 constexpr auto get() const & noexcept -> const T& {
65 KOKKOS_ASSERT(m_has_value);
66 return m_storage.__get();
67 }
68
69 constexpr auto get() && noexcept -> T&& {
70 KOKKOS_ASSERT(m_has_value);
71 return std::move(m_storage.__get());
72 }
73
74 constexpr auto get() const && noexcept -> const T&& = delete;
75
76 constexpr auto operator->() noexcept -> T* {
77 KOKKOS_ASSERT(m_has_value);
78 return m_storage.operator->();
79 }
80
81 constexpr auto operator->() const noexcept -> const T* {
82 KOKKOS_ASSERT(m_has_value);
83 return m_storage.operator->();
84 }
85
86 constexpr explicit operator bool() const noexcept {
87 return m_has_value;
88 }
89
90 constexpr bool has_value() const noexcept {
91 return m_has_value;
92 }
93
94 private:
95 stdexec::__manual_lifetime<T> m_storage{};
96 bool m_has_value{false};
97};
98
99} // namespace Kokkos::Execution::Impl
100
101#endif // KOKKOS_EXECUTION_IMPL_OPTIONAL_STORAGE_HPP
OptionalStorage(const OptionalStorage &)=delete
constexpr auto emplace_from(Func &&func, Args &&... args) noexcept(noexcept(T{std::forward< Func >(func)(std::forward< Args >(args)...)})) -> T &
OptionalStorage(OptionalStorage &&)=delete
constexpr auto get() &noexcept -> T &
OptionalStorage & operator=(const OptionalStorage &)=delete
constexpr auto get() const &&noexcept -> const T &&=delete
constexpr OptionalStorage() noexcept=default
constexpr auto emplace(Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) -> T &
OptionalStorage & operator=(OptionalStorage &&)=delete
constexpr auto get() &&noexcept -> T &&
constexpr bool has_value() const noexcept
constexpr auto get() const &noexcept -> const T &
constexpr auto operator->() const noexcept -> const T *
stdexec::__manual_lifetime< T > m_storage