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;
PEAK_COMMON_NO_DISCARD const T & AnyCast() const
Const version of AnyCast.
Definition peak_common_any.hpp:201
PEAK_COMMON_NO_DISCARD const std::type_info & GetType() const
Gets the type of the stored value.
Definition peak_common_any.hpp:164
Any & operator=(const Any &other)
Copy assignment operator.
Definition peak_common_any.hpp:131
Any()=default
Default constructor. Constructs an empty Any object.
void Reset()
Clears the stored value.
Definition peak_common_any.hpp:152
Any(T &&value)
Constructs an Any from a rvalue reference.
Definition peak_common_any.hpp:101
Any(Any &&other) noexcept=default
Move constructor.
Any(const Any &other)
Copy constructor.
Definition peak_common_any.hpp:115
Any(const T &value)
Constructs an Any from a const reference.
Definition peak_common_any.hpp:88
Any & operator=(Any &&other) noexcept=default
Move assignment operator.
T & AnyCast()
Casts the stored value to the specified type.
Definition peak_common_any.hpp:179
PEAK_COMMON_NO_DISCARD bool HasValue() const
Checks if the Any contains a value.
Definition peak_common_any.hpp:220
Thrown when a cast to an incompatible type is attempted.
Definition peak_common_exceptions.hpp:85
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:22