39 virtual ~Placeholder() =
default;
46 struct Holder :
public Placeholder
50 explicit Holder(
const T& val)
54 explicit Holder(T&& val)
55 : value(std::move(val))
65 return std::make_unique<Holder<T>>(value);
69 std::unique_ptr<Placeholder> m_content;
88 explicit Any(
const T& value)
89 : m_content(std::make_unique<Holder<typename std::decay_t<T>>>(value))
100 template <
typename T>
104 typename std::enable_if<!std::is_same<
Any,
typename std::decay<T>::type>::value>::type* =
nullptr
107 : m_content(std::make_unique<Holder<typename std::decay_t<T>>>(std::forward<T>(value)))
116 : m_content(other.m_content ? other.m_content->Clone() : nullptr)
135 m_content = other.m_content ? other.m_content->Clone() :
nullptr;
166 return m_content ? m_content->Type() :
typeid(void);
178 template <
typename T>
181 using namespace std::string_literals;
186 "Casting from "s +
typeid(T).name() +
" to the given type " +
GetType().name() +
" is not supported!");
188 return static_cast<Holder<T>*
>(m_content.get())->value;
200 template <
typename T>
203 using namespace std::string_literals;
208 "Casting from "s +
typeid(T).name() +
" to the given type " +
GetType().name() +
" is not supported!");
210 return static_cast<const Holder<T>*
>(m_content.get())->value;
222 return m_content !=
nullptr;
A type-erased container for any copyable value.
Any & operator=(const Any &other)
Copy assignment operator.
Any()=default
Default constructor. Constructs an empty Any object.
const std::type_info & GetType() const
Gets the type of the stored value.
void Reset()
Clears the stored value.
Any(T &&value)
Constructs an Any from a rvalue reference.
const T & AnyCast() const
Const version of AnyCast.
Any(Any &&other) noexcept=default
Move constructor.
Any(const Any &other)
Copy constructor.
Any(const T &value)
Constructs an Any from a const reference.
Any & operator=(Any &&other) noexcept=default
Move assignment operator.
T & AnyCast()
Casts the stored value to the specified type.
bool HasValue() const
Checks if the Any contains a value.
Thrown when a cast to an incompatible type is attempted.
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.