30#include <TGUI/Config.hpp>
36#if TGUI_COMPILED_WITH_CPP_VER >= 17
42#if TGUI_COMPILED_WITH_CPP_VER >= 17
46 T AnyCast(
const Any& obj)
48 return std::any_cast<T>(obj);
54 using StorageType = std::decay_t<T>;
56 TGUI_NODISCARD
bool is_null()
const
58 return ptr ==
nullptr;
61 TGUI_NODISCARD
bool not_null()
const
63 return ptr !=
nullptr;
68 : ptr{new Derived<StorageType<U>>(std::forward<U>(value))}
72 TGUI_NODISCARD
bool has_value() const noexcept
74 return ptr !=
nullptr;
78 TGUI_NODISCARD
bool is()
const
80 using T = StorageType<U>;
81 return (
dynamic_cast<Derived<T>*
>(ptr) !=
nullptr);
85 StorageType<U>& as()
const
87 using T = StorageType<U>;
88 auto derived =
dynamic_cast<Derived<T>*
>(ptr);
90 throw std::bad_cast();
92 return derived->value;
98 return as<StorageType<U>>();
111 Any(Any&& that) noexcept
117 Any& operator=(
const Any& a)
119 if ((
this == &a) || (ptr == a.ptr))
132 Any& operator=(Any&& a)
noexcept
134 if ((
this == &a) || (ptr == a.ptr))
137 std::swap(ptr, a.ptr);
150 virtual ~Base() =
default;
151 TGUI_NODISCARD
virtual Base* clone()
const = 0;
155 struct Derived : Base
159 value(std::forward<U>(val))
163 Base* clone()
const override
165 return new Derived<T>(value);
171 TGUI_NODISCARD Base* clone()
const
183 TGUI_NODISCARD T AnyCast(
const Any& obj)
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36