64 template<
typename ValueType>
65 Any(
const ValueType& value) :
66 mContent(std::make_unique<Holder<ValueType>>(value))
70 template<
typename ValueType>
73 mContent = std::make_unique<Holder>(rhs);
77 Any& operator=(
const Any& rhs);
82 const std::type_info& getType()
const;
84 template<
typename ValueType>
87 if (this->getType() ==
typeid(ValueType))
88 return &
static_cast<Any::Holder<ValueType>*
>(this->mContent.get())->held;
91 "Bad cast from type '" << getType().name() <<
"' to '" <<
typeid(ValueType).name() <<
"'");
95 bool compare(
const Any& other)
const;
101 virtual ~Placeholder() =
default;
104 virtual const std::type_info& getType()
const = 0;
105 virtual std::unique_ptr<Placeholder> clone()
const = 0;
106 virtual bool compare(
const std::unique_ptr<Placeholder>& other)
const = 0;
110 struct HasOperatorEqualImpl
113 static auto test(U*) ->
decltype(std::declval<U>() == std::declval<U>());
115 static auto test(...) -> std::false_type;
117 using type =
typename std::is_same<bool, decltype(test<T>(
nullptr))>::type;
118 static constexpr bool value = type::value;
122 struct HasOperatorEqual : HasOperatorEqualImpl<T>::type
125 template<
typename T1,
typename T2>
126 struct HasOperatorEqual<std::pair<T1, T2>>
128 static constexpr bool value = HasOperatorEqualImpl<T1>::value && HasOperatorEqualImpl<T2>::value;
131 template<
typename ValueType>
132 class Holder :
public Placeholder
137 Holder(
const ValueType& value) :
143 const std::type_info& getType()
const override
145 return typeid(ValueType);
148 std::unique_ptr<Placeholder> clone()
const override
150 return std::make_unique<Holder>(held);
153 bool compare(
const std::unique_ptr<Placeholder>& other)
const override
155 if constexpr (HasOperatorEqual<ValueType>::value)
156 return getType() == other->getType() && held ==
static_cast<Holder*
>(other.get())->held;
158 MYGUI_EXCEPT(
"Type '" << getType().name() <<
"' is not comparable");
166 std::unique_ptr<Placeholder> mContent;