34 virtual ~Placeholder() =
default;
41 struct Holder :
public Placeholder
45 explicit Holder(
const T& val)
49 explicit Holder(T&& val)
50 : value(std::move(val))
60 return std::make_unique<Holder<T>>(value);
64 std::unique_ptr<Placeholder> m_content;
83 explicit Any(
const T& value)
84 : m_content(std::make_unique<Holder<typename std::decay_t<T>>>(value))
96 explicit Any(T&& value
99 typename std::enable_if<!std::is_same<
Any,
typename std::decay<T>::type>::value>::type* =
nullptr
102 : m_content(std::make_unique<Holder<typename std::decay_t<T>>>(std::forward<T>(value)))
111 : m_content(other.m_content ? other.m_content->Clone() : nullptr)
130 m_content = other.m_content ? other.m_content->Clone() :
nullptr;
161 return m_content ? m_content->Type() :
typeid(void);
173 template <
typename T>
176 using namespace std::string_literals;
181 "Casting from "s +
GetType().name() +
" to the given type " +
typeid(T).name() +
" is not supported!");
183 return static_cast<Holder<T>*
>(m_content.get())->value;
195 template <
typename T>
198 using namespace std::string_literals;
203 "Casting from "s +
GetType().name() +
" to the given type " +
typeid(T).name() +
" is not supported!");
205 return static_cast<const Holder<T>*
>(m_content.get())->value;
217 return m_content !=
nullptr;
Any(T &&value)
Constructs an Any from a rvalue reference.
Definition peak_common_any.hpp:96
T & AnyCast()
Casts the stored value to the specified type.
Definition peak_common_any.hpp:174
void Reset()
Clears the stored value.
Definition peak_common_any.hpp:147
Any(Any &&other) noexcept=default
Move constructor.
PEAK_COMMON_NO_DISCARD const T & AnyCast() const
Const version of AnyCast.
Definition peak_common_any.hpp:196
Any()=default
Default constructor. Constructs an empty Any object.
Any & operator=(const Any &other)
Copy assignment operator.
Definition peak_common_any.hpp:126
PEAK_COMMON_NO_DISCARD bool HasValue() const
Checks if the Any contains a value.
Definition peak_common_any.hpp:215
Any & operator=(Any &&other) noexcept=default
Move assignment operator.
Any(const Any &other)
Copy constructor.
Definition peak_common_any.hpp:110
Any(const T &value)
Constructs an Any from a const reference.
Definition peak_common_any.hpp:83
PEAK_COMMON_NO_DISCARD const std::type_info & GetType() const
Gets the type of the stored value.
Definition peak_common_any.hpp:159
Thrown when a cast to an incompatible type is attempted.
Definition peak_common_exceptions.hpp:88
Root namespace for common types and interfaces shared across multiple libraries.
Definition peak_common_math.hpp:17
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89