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_Core.hpp"
7
8
namespace
Kokkos::Execution::Impl
{
9
20
template
<
typename
T>
21
class
OptionalStorage
{
22
public
:
23
constexpr
OptionalStorage
() noexcept = default;
24
25
constexpr ~
OptionalStorage
() {
26
if
(
m_has_value
) {
27
m_storage
.__destroy();
28
}
29
}
30
31
OptionalStorage
(
const
OptionalStorage
&) =
delete
;
32
OptionalStorage
(
OptionalStorage
&&) =
delete
;
33
OptionalStorage
&
operator=
(
const
OptionalStorage
&) =
delete
;
34
OptionalStorage
&
operator=
(
OptionalStorage
&&) =
delete
;
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
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:45
Kokkos::Execution::Impl::OptionalStorage::OptionalStorage
OptionalStorage(OptionalStorage &&)=delete
Kokkos::Execution::Impl::OptionalStorage::reset
constexpr void reset() noexcept
Definition
optional_storage.hpp:53
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() &noexcept -> T &
Definition
optional_storage.hpp:59
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:96
Kokkos::Execution::Impl::OptionalStorage::emplace
constexpr auto emplace(Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) -> T &
Definition
optional_storage.hpp:37
Kokkos::Execution::Impl::OptionalStorage::operator=
OptionalStorage & operator=(OptionalStorage &&)=delete
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() &&noexcept -> T &&
Definition
optional_storage.hpp:69
Kokkos::Execution::Impl::OptionalStorage::has_value
constexpr bool has_value() const noexcept
Definition
optional_storage.hpp:90
Kokkos::Execution::Impl::OptionalStorage::get
constexpr auto get() const &noexcept -> const T &
Definition
optional_storage.hpp:64
Kokkos::Execution::Impl::OptionalStorage::operator->
constexpr auto operator->() const noexcept -> const T *
Definition
optional_storage.hpp:81
Kokkos::Execution::Impl::OptionalStorage::m_storage
stdexec::__manual_lifetime< T > m_storage
Definition
optional_storage.hpp:95
stdexec.hpp
Kokkos::Execution::Impl
Definition
attributes.hpp:6
kokkos-execution
impl
optional_storage.hpp
Generated on
for kokkos-execution by
1.18.0