73 template<
typename ValueType>
74 Any(
const ValueType& value) :
75 mContent(new Holder<ValueType>(value))
83 template<
typename ValueType>
84 Any& operator = (
const ValueType& rhs)
91 Any& operator = (
const Any& rhs);
95 const std::type_info& getType()
const;
97 template<
typename ValueType>
100 if (this->getType() ==
typeid(ValueType))
101 return &
static_cast<Any::Holder<ValueType> *
>(this->mContent)->held;
102 MYGUI_ASSERT(!_throw,
"Bad cast from type '" << getType().name() <<
"' to '" <<
typeid(ValueType).name() <<
"'");
106 void* castUnsafe()
const;
108 bool compare(
const Any& other)
const;
114 virtual ~Placeholder() =
default;
117 virtual const std::type_info& getType()
const = 0;
118 virtual Placeholder* clone()
const = 0;
119 virtual bool compare(Placeholder* other)
const = 0;
123 struct HasOperatorEqualImpl
125 template <
typename U>
126 static auto test(U*) -> decltype(std::declval<U>() == std::declval<U>());
128 static auto test(...)->std::false_type;
130 using type =
typename std::is_same<bool, decltype(test<T>(
nullptr))>::type;
131 static constexpr
bool value = type::value;
135 struct HasOperatorEqual : HasOperatorEqualImpl<T>::type {};
136 template<
typename T1,
typename T2>
137 struct HasOperatorEqual<std::pair<T1, T2>>
139 static constexpr
bool value = HasOperatorEqualImpl<T1>::value && HasOperatorEqualImpl<T2>::value;
142 template<
typename ValueType>
147 Holder(
const ValueType& value) :
152 Holder& operator=(
const Holder&) =
delete;
155 const std::type_info& getType()
const override
157 return typeid(ValueType);
160 Placeholder* clone()
const override
162 return new Holder(held);
165 bool compare(Placeholder* other)
const override
167 return compareImpl(other);
170 template<
typename T = ValueType>
171 typename std::enable_if<HasOperatorEqual<T>::value ==
true,
bool>::type compareImpl(Placeholder* other)
const
173 return getType() == other->getType() && held ==
static_cast<Holder*
>(other)->held;
176 template<
typename T = ValueType>
177 typename std::enable_if<HasOperatorEqual<T>::value ==
false,
bool>::type compareImpl(Placeholder* other)
const
179 MYGUI_EXCEPT(
"Type '" << getType().name() <<
"' is not comparable");
187 Placeholder* mContent;
192 #endif // MYGUI_ANY_H_