30#include <TGUI/Config.hpp>
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
33 #include <type_traits>
37 #if TGUI_COMPILED_WITH_CPP_VER >= 17
42TGUI_MODULE_EXPORT
namespace tgui
44#if TGUI_COMPILED_WITH_CPP_VER >= 17
48 T AnyCast(
const Any& obj)
50 return std::any_cast<T>(obj);
56 using StorageType = std::decay_t<T>;
58 TGUI_NODISCARD
bool is_null()
const
60 return ptr ==
nullptr;
63 TGUI_NODISCARD
bool not_null()
const
65 return ptr !=
nullptr;
70 : ptr{new Derived<StorageType<U>>(std::forward<U>(value))}
74 TGUI_NODISCARD
bool has_value() const noexcept
76 return ptr !=
nullptr;
80 TGUI_NODISCARD
bool is()
const
82 using T = StorageType<U>;
83 return (
dynamic_cast<Derived<T>*
>(ptr) !=
nullptr);
87 StorageType<U>& as()
const
89 using T = StorageType<U>;
90 auto derived =
dynamic_cast<Derived<T>*
>(ptr);
92 throw std::bad_cast();
94 return derived->value;
100 return as<StorageType<U>>();
113 Any(Any&& that) noexcept
119 Any& operator=(
const Any& a)
121 if ((
this == &a) || (ptr == a.ptr))
134 Any& operator=(Any&& a)
noexcept
136 if ((
this == &a) || (ptr == a.ptr))
139 std::swap(ptr, a.ptr);
152 virtual ~Base() =
default;
153 TGUI_NODISCARD
virtual Base* clone()
const = 0;
157 struct Derived : Base
161 value(std::forward<U>(val))
165 Base* clone()
const override
167 return new Derived<T>(value);
173 TGUI_NODISCARD Base* clone()
const
185 TGUI_NODISCARD T AnyCast(
const Any& obj)
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38