kokkos-execution
0.0.1
Toggle main menu visibility
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
4
#include "
kokkos-execution/stdexec.hpp
"
5
6
#include "Kokkos_Macros.hpp"
7
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8
import
kokkos.core;
9
# include "Kokkos_Assert.hpp"
10
#else
11
# include "Kokkos_Core.hpp"
12
#endif
13
14
namespace
Kokkos::Execution::Impl
{
15
26
template
<
typename
T>
27
class
OptionalStorage
{
28
public
:
29
constexpr
OptionalStorage
() noexcept = default;
30
31
constexpr ~
OptionalStorage
() {
32
if
(
m_has_value
) {
33
m_storage
.__destroy();
34
}
35
}
36
37
OptionalStorage
(
const
OptionalStorage
&) =
delete
;
38
OptionalStorage
(
OptionalStorage
&&) =
delete
;
39
OptionalStorage
&
operator=
(
const
OptionalStorage
&) =
delete
;
40
OptionalStorage
&
operator=
(
OptionalStorage
&&) =
delete
;
41
42
template
<
typename
... Args>
43
constexpr
auto
emplace
(Args&&... args)
noexcept
(std::is_nothrow_constructible_v<T, Args...>) -> T& {
44
KOKKOS_ASSERT(!
m_has_value
);
45
auto
& ref =
m_storage
.__construct(std::forward<Args>(args)...);
46
m_has_value
=
true
;
47
return
ref;
48
}
49
50
template
<
typename
Func,
typename
... Args>
51
constexpr
auto
emplace_from
(Func&& func, Args&&... args)
52
noexcept
(
noexcept
(T{std::forward<Func>(func)(std::forward<Args>(args)...)})) -> T& {
53
KOKKOS_ASSERT(!
m_has_value
);
54
auto
& ref =
m_storage
.__construct_from(std::forward<Func>(func), std::forward<Args>(args)...);
55
m_has_value
=
true
;
56
return
ref;
57
}
58
59
constexpr
void
reset
() noexcept {
60
KOKKOS_ASSERT(
m_has_value
);
61
m_storage
.__destroy();
62
m_has_value
=
false
;
63
}
64
65
constexpr
auto
get
() &
noexcept
-> T& {
66
KOKKOS_ASSERT(
m_has_value
);
67
return
m_storage
.__get();
68
}
69
70
constexpr
auto
get
() const & noexcept -> const T& {
71
KOKKOS_ASSERT(
m_has_value
);
72
return
m_storage
.__get();
73
}
74
75
constexpr
auto
get
() &&
noexcept
-> T&& {
76
KOKKOS_ASSERT(
m_has_value
);
77
return
std::move(
m_storage
.__get());
78
}
79
80
constexpr
auto
get
() const && noexcept -> const T&& = delete;
81
82
constexpr auto operator->() noexcept -> T* {
83
KOKKOS_ASSERT(
m_has_value
);
84
return
m_storage
.operator->();
85
}
86
87
constexpr
auto
operator->
() const noexcept -> const T* {
88
KOKKOS_ASSERT(
m_has_value
);
89
return
m_storage
.operator->();
90
}
91
92
constexpr
explicit
operator
bool() const noexcept {
93
return
m_has_value
;
94
}
95
96
constexpr
bool
has_value
() const noexcept {
97
return
m_has_value
;
98
}
99
100
private
:
101
stdexec::__manual_lifetime<T>
m_storage
{};
102
bool
m_has_value
{
false
};
103
};
104
105
}
// namespace Kokkos::Execution::Impl
106
107
#endif
// KOKKOS_EXECUTION_IMPL_OPTIONAL_STORAGE_HPP
Kokkos::Execution::Impl::OptionalStorage::OptionalStorage
OptionalStorage(const OptionalStorage &)=delete
Kokkos::Execution::Impl::OptionalStorage::emplace_from
constexpr auto emplace_from(Func &&func, Args &&... args) noexcept(noexcept(T{std::forward< Func >(func)(std::forward< Args >(args)...)})) -> T &
Definition
optional_storage.hpp:51
Kokkos::Execution::Impl::OptionalStorage::OptionalStorage
OptionalStorage(OptionalStorage &&)=delete
Kokkos::Execution::Impl::OptionalStorage::reset
constexpr void reset() noexcept
Definition
optional_storage.hpp:59
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() &noexcept -> T &
Definition
optional_storage.hpp:65
Kokkos::Execution::Impl::OptionalStorage::operator=
OptionalStorage & operator=(const OptionalStorage &)=delete
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() const &&noexcept -> const T &&=delete
Kokkos::Execution::Impl::OptionalStorage::OptionalStorage
constexpr OptionalStorage() noexcept=default
Kokkos::Execution::Impl::OptionalStorage::m_has_value
bool m_has_value
Definition
optional_storage.hpp:102
Kokkos::Execution::Impl::OptionalStorage::emplace
constexpr auto emplace(Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) -> T &
Definition
optional_storage.hpp:43
Kokkos::Execution::Impl::OptionalStorage::operator=
OptionalStorage & operator=(OptionalStorage &&)=delete
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() &&noexcept -> T &&
Definition
optional_storage.hpp:75
Kokkos::Execution::Impl::OptionalStorage::has_value
constexpr bool has_value() const noexcept
Definition
optional_storage.hpp:96
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() const &noexcept -> const T &
Definition
optional_storage.hpp:70
Kokkos::Execution::Impl::OptionalStorage::operator->
constexpr auto operator->() const noexcept -> const T *
Definition
optional_storage.hpp:87
Kokkos::Execution::Impl::OptionalStorage::m_storage
stdexec::__manual_lifetime< T > m_storage
Definition
optional_storage.hpp:101
stdexec.hpp
Kokkos::Execution::Impl
Definition
attributes.hpp:6
kokkos-execution
impl
optional_storage.hpp
Generated on
for kokkos-execution by
1.18.0