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
18template <typename T>
20 public:
21 constexpr OptionalStorage() noexcept = default;
22
23 constexpr ~OptionalStorage() {
24 if (m_has_value) {
25 m_storage.__destroy();
26 }
27 }
28
33
34 template <typename... Args>
35 constexpr auto emplace(Args&&... args) noexcept(std::is_nothrow_constructible_v<T, Args...>) -> T& {
36 KOKKOS_ASSERT(!m_has_value);
37 auto& ref = m_storage.__construct(std::forward<Args>(args)...);
38 m_has_value = true;
39 return ref;
40 }
41
42 template <typename Func, typename... Args>
43 constexpr auto emplace_from(Func&& func, Args&&... args)
44 noexcept(noexcept(T{std::forward<Func>(func)(std::forward<Args>(args)...)})) -> T& {
45 KOKKOS_ASSERT(!m_has_value);
46 auto& ref = m_storage.__construct_from(std::forward<Func>(func), std::forward<Args>(args)...);
47 m_has_value = true;
48 return ref;
49 }
50
51 constexpr void reset() noexcept {
52 KOKKOS_ASSERT(m_has_value);
53 m_storage.__destroy();
54 m_has_value = false;
55 }
56
57 constexpr auto get() & noexcept -> T& {
58 KOKKOS_ASSERT(m_has_value);
59 return m_storage.__get();
60 }
61
62 constexpr auto get() const & noexcept -> const T& {
63 KOKKOS_ASSERT(m_has_value);
64 return m_storage.__get();
65 }
66
67 constexpr auto get() && noexcept -> T&& {
68 KOKKOS_ASSERT(m_has_value);
69 return std::move(m_storage.__get());
70 }
71
72 constexpr auto get() const && noexcept -> const T&& = delete;
73
74 constexpr auto operator->() noexcept -> T* {
75 KOKKOS_ASSERT(m_has_value);
76 return m_storage.operator->();
77 }
78
79 constexpr auto operator->() const noexcept -> const T* {
80 KOKKOS_ASSERT(m_has_value);
81 return m_storage.operator->();
82 }
83
84 constexpr explicit operator bool() const noexcept {
85 return m_has_value;
86 }
87
88 constexpr bool has_value() const noexcept {
89 return m_has_value;
90 }
91
92 private:
93 stdexec::__manual_lifetime<T> m_storage{};
94 bool m_has_value{false};
95};
96
97} // namespace Kokkos::Execution::Impl
98
99#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