16 template <
class Enum,
template <Enum>
class T, Enum Default = Enum{}>
26 template <enum_type E>
41 template <enum_type E>
42 [[nodiscard]] T<E>
const &
get()
const;
44 template <enum_type E>
45 [[nodiscard]] T<E> &
get();
47 template <enum_type E>
73 template <enum_type E,
class U>
86 template <enum_type E>
88 sizeof(T<E>) <=
sizeof(std::uintptr_t) and (
alignof(std::uintptr_t) %
alignof(T<E>)) == 0 and std::is_trivial_v<T<E>>;
103 template <enum_type E>
106 template <enum_type E>
164 template <
class Enum,
template <Enum>
class T, Enum Default>
166 *
this = std::move(other);
169 template <
class Enum,
template <Enum>
class T, Enum Default>
171 if (&other !=
this) {
172 std::swap(_deleter, other._deleter);
173 std::swap(_storage, other._storage);
174 std::swap(_active, other._active);
179 template <
class Enum,
template <Enum>
class T, Enum Default>
182 template <
class Enum,
template <Enum>
class T, Enum Default>
188 template <
class Enum,
template <Enum>
class T, Enum Default>
191 template <
class Enum,
template <Enum>
class T, Enum Default>
196 template <
class Enum,
template <Enum>
class T, Enum Default>
201 template <
class Enum,
template <Enum>
class T, Enum Default>
205 if constexpr (can_be_stored_in_place_v<E>) {
206 return *
reinterpret_cast<T<E>
const *
>(storage_in_place());
208 assert_holds_memory();
209 return *
reinterpret_cast<T<E>
const *
>(storage_allocated());
213 template <
class Enum,
template <Enum>
class T, Enum Default>
217 if constexpr (can_be_stored_in_place_v<E>) {
218 return *
reinterpret_cast<T<E> *
>(storage_in_place());
220 assert_holds_memory();
221 return *
reinterpret_cast<T<E> *
>(storage_allocated());
225 template <
class Enum,
template <Enum>
class T, Enum Default>
228 set<E>(std::move(obj));
233 template <
class Enum,
template <Enum>
class T, Enum Default>
234 template <Enum E,
class U>
236 if constexpr (can_be_stored_in_place_v<E>) {
240 *
reinterpret_cast<T<E> *
>(storage_in_place()) = std::forward<U>(obj);
244 if (type() == E and holds_memory()) {
246 *
reinterpret_cast<T<E> *
>(storage_allocated()) = std::forward<U>(obj);
250 storage_allocated() =
new T<E>(std::forward<U>(obj));
251 _deleter = get_default_deleter<E>();
258 template <
class Enum,
template <Enum>
class T, Enum Default>
261 LOGE(
"MLAB",
"any_of holds <type %d>, cannot get reference to <type %d>.",
262 static_cast<unsigned>(type()),
static_cast<unsigned>(e));
267 template <
class Enum,
template <Enum>
class T, Enum Default>
269 if (not holds_memory()) {
270 LOGE(
"MLAB",
"any_of is empty, cannot get reference.");
275 template <
class Enum,
template <Enum>
class T, Enum Default>
278 if (holds_memory()) {
280 _deleter(storage_allocated());
284 storage_allocated() =
nullptr;
287 template <
class Enum,
template <Enum>
class T, Enum Default>
290 return &default_deleter_fn<E>;
293 template <
class Enum,
template <Enum>
class T, Enum Default>
296 auto *typed_ptr =
reinterpret_cast<T<E> *
>(ptr);
300 template <
class Enum,
template <Enum>
class T, Enum Default>
302 return _deleter !=
nullptr;
305 template <
class Enum,
template <Enum>
class T, Enum Default>
307 return *
reinterpret_cast<void const *
const *
>(&_storage);
310 template <
class Enum,
template <Enum>
class T, Enum Default>
312 return *
reinterpret_cast<void **
>(&_storage);
315 template <
class Enum,
template <Enum>
class T, Enum Default>
317 return reinterpret_cast<void const *
>(&_storage);
320 template <
class Enum,
template <Enum>
class T, Enum Default>
322 return reinterpret_cast<void *
>(&_storage);
any_of(any_of const &)=delete
Enum enum_type
Definition any_of.hpp:21
any_of(T< E > obj)
Definition any_of.hpp:184
any_of(any_of &&other) noexcept
Definition any_of.hpp:165
any_of & operator=(any_of const &)=delete
any_of()
Definition any_of.hpp:189
any_of(enum_type e)
Definition any_of.hpp:180
static constexpr enum_type default_type
Definition any_of.hpp:22
void(*)(void *) deleter_type
Definition any_of.hpp:80
void free()
Definition any_of.hpp:276
T< E > & get()
Definition any_of.hpp:215
T< E > value_type
Definition any_of.hpp:20
static constexpr deleter_type get_default_deleter()
Definition any_of.hpp:289
~any_of()
Definition any_of.hpp:192
static constexpr bool can_be_stored_in_place_v
Definition any_of.hpp:87
void set(U &&obj)
Definition any_of.hpp:235
void assert_holds_memory() const
Definition any_of.hpp:268
any_of & operator=(T< E > obj)
void assert_type_is(enum_type e) const
Definition any_of.hpp:259
enum_type type() const
Definition any_of.hpp:197
any_of & operator=(any_of &&other) noexcept
Definition any_of.hpp:170
T< E > const & get() const
bool holds_memory() const
Definition any_of.hpp:301
static void default_deleter_fn(void *ptr)
Definition any_of.hpp:295
deleter_type _deleter
Definition any_of.hpp:97
enum_type _active
Definition any_of.hpp:95
std::uintptr_t _storage
Definition any_of.hpp:96
void const * storage_allocated() const
Definition any_of.hpp:306
void *& storage_allocated()
Definition any_of.hpp:311
void * storage_in_place()
Definition any_of.hpp:321
void const * storage_in_place() const
Definition any_of.hpp:316
#define LOGE(tag, format,...)
Definition log.hpp:35
result_content
Definition result.hpp:15