24#include "internal/AnyImpl.h"
47 struct is_amino_array : std::false_type {};
49 struct is_amino_array<
Amino::
Array<T>> : std::true_type {};
53 using bool_t = std::integral_constant<bool, Bool>;
57 template <
typename ValueType,
typename T = std::decay_t<ValueType>>
60 !std::is_same<Any, T>::value &&
64 !is_amino_array<T>::value &&
69 !std::is_same<Amino::StringView, T>::value &&
72 !std::is_pointer<T>::value &&
75 !std::is_array<ValueType>::value &&
76 !std::is_array<std::remove_reference_t<ValueType>>::value)>;
80 template <
typename ValueType,
typename T = std::decay_t<ValueType>>
87 std::is_copy_constructible<T>::value &&
90 std::is_standard_layout<T>::value)>;
93 template <
typename ValueType>
97 template <
typename ValueType,
typename... Args>
99 std::is_constructible<std::decay_t<ValueType>, Args...>::value>;
180class Any :
private Internal::AnyImpl::AnyUntyped {
181 using Base = Internal::AnyImpl::AnyUntyped;
220 template <typename ValueType, typename =
Traits::enable_if_valid<ValueType>>
221 explicit
Any(ValueType&& v) noexcept : Base(
std::forward<ValueType>(v)) {}
252 template <
typename ValueType,
typename = Traits::enable_if_val
id<ValueType>>
254 Any(std::forward<ValueType>(rhs)).swap(*
this);
275 typename = Traits::enable_if_valid<ValueType>,
278 Base::emplace<ValueType>(std::forward<Args>(args)...);
299 typename IL = std::initializer_list<Up>,
300 typename = Traits::enable_if_valid<ValueType>,
302 void emplace(std::initializer_list<Up> il, Args&&... args)
noexcept {
303 Base::emplace<ValueType>(il, std::forward<Args>(args)...);
311 void reset() noexcept { Base::reset(); }
320 bool has_value() const noexcept {
return Base::has_value(); }
323 bool has_same_type(
Any const& other) const noexcept {
324 return type() == other.type();
333 friend Internal::RuntimeAny;
334 friend Internal::AnyCast;
342 std::is_standard_layout<Any>::value,
343 "Amino::Any must be standard layout. ");
345 sizeof(Any) == Internal::AnyTraits::sBufferSize +
sizeof(
void*),
346 "Incorrect Amino::Any size");
348 alignof(Any) == Internal::AnyTraits::sBufferAlign,
349 "Incorrect Amino::Any alignment");
358inline void swap(
Any& lhs,
Any& rhs)
noexcept { lhs.swap(rhs); }
379 typename = std::enable_if_t<!std::is_same<void, ValueType>::value>>
380inline std::add_pointer_t<std::add_const_t<ValueType>>
any_cast(
381 Any const* v)
noexcept {
384 "ValueType must be a valid payload type");
385 if (!v)
return nullptr;
386 return Internal::AnyCast::cast<ValueType>(v);
403 typename = std::enable_if_t<!std::is_same<void, ValueType>::value>>
407 "ValueType must be a valid payload type");
408 if (!v)
return nullptr;
409 return Internal::AnyCast::cast<ValueType>(v);
434 typename = std::enable_if_t<std::is_same<void, ValueType>::value>>
437 if (!v)
return nullptr;
438 return Internal::AnyCast::cast<void>(v);
454template <
typename ValueType>
458 "ValueType must be a valid payload type");
459 using Tp = std::add_const_t<std::remove_reference_t<ValueType>>;
460 Tp* tmp = any_cast<Tp>(&v);
461 return tmp ? *tmp : ValueType();
480template <
typename ValueType>
484 "ValueType must be a valid payload type");
485 using Tp = std::add_const_t<std::remove_reference_t<ValueType>>;
486 Any any{std::move(v)};
487 Tp* tmp = any_cast<Tp>(&any);
488 return tmp ? std::move(*tmp) : ValueType();
std::add_pointer_t< std::add_const_t< ValueType > > any_cast(Any const *v) noexcept
Cast an instance of Any to a payload type.
AMINO_INTERNAL_DEPRECATED("Amino::isJobCancelled is deprecated and now always returns false. " "Use a 'StopToken const& jobport instead. ") inline bool isJobCancelled()
void swap(Any &lhs, Any &rhs) noexcept
Swap the payloads of two instances of Any.
Traits about the to-be-payload of an Amino::Any.
bool_t<(!std::is_same< Any, T >::value &&!is_amino_array< T >::value &&!std::is_same< Amino::StringView, T >::value &&!std::is_pointer< T >::value &&!std::is_array< ValueType >::value &&!std::is_array< std::remove_reference_t< ValueType > >::value)> is_cast_enabled
Whether a Any can be queried to extract its payload as type T.
std::enable_if_t< is_valid< ValueType >::value > enable_if_valid
Enable if the type is a valid payload type.
std::enable_if_t< std::is_constructible< std::decay_t< ValueType >, Args... >::value > enable_if_constructible
Enable if the type can be constructed from the given arguments.
bool_t<(is_cast_enabled< ValueType >::value &&std::is_copy_constructible< T >::value &&std::is_standard_layout< T >::value)> is_valid
Whether a type T is a valid payload type. (i.e. can be assigned in an Any).
Generic value class that allows for storage of a value of any type.
AMINO_INTERNAL_DEPRECATED("Use any.type() == other.type() instead.") bool has_same_type(Any const &other) const noexcept
Any & swap(Any &rhs) noexcept
Swap payloads with another Any object.
Any & operator=(Any &&rhs) noexcept=default
Move assignment operator.
void emplace(Args &&... args) noexcept
Replaces the contained object of this Any.
Any & operator=(ValueType &&rhs) &noexcept
Move assignment conversion.
Any & operator=(Any const &rhs)=default
Copy assignment operator.
void emplace(std::initializer_list< Up > il, Args &&... args) noexcept
Replaces the contained object of this Any.
void reset() noexcept
Reset this Any object.
~Any()=default
Destructor.
bool has_value() const noexcept
Return true if this Any object contains a payload.
TypeId type() const noexcept
Returns the TypeId of the value in this Any, or the TypeId of void if this Any does not have a value.
Any() noexcept=default
Default constructor.
Define a Amino array of elements of type T.
Type identifier for a type.