65 template<
typename ValueType>
66 Any(
const ValueType& value) :
67 mContent(new Holder<ValueType>(value))
75 template<
typename ValueType>
76 Any& operator = (
const ValueType& rhs)
83 Any& operator = (
const Any& rhs);
87 const std::type_info& getType()
const;
89 template<
typename ValueType>
92 if (this->getType() ==
typeid(ValueType))
93 return &
static_cast<Any::Holder<ValueType> *
>(this->mContent)->held;
94 MYGUI_ASSERT(!_throw,
"Bad cast from type '" << getType().name() <<
"' to '" <<
typeid(ValueType).name() <<
"'");
98 void* castUnsafe()
const;
100 bool compare(
const Any& other)
const;
106 virtual ~Placeholder() =
default;
109 virtual const std::type_info& getType()
const = 0;
110 virtual Placeholder* clone()
const = 0;
111 virtual bool compare(Placeholder* other)
const = 0;
115 struct HasOperatorEqualImpl
117 template <
typename U>
118 static auto test(U*) ->
decltype(std::declval<U>() == std::declval<U>());
120 static auto test(...)->std::false_type;
122 using type =
typename std::is_same<bool, decltype(test<T>(
nullptr))>::type;
123 static constexpr bool value = type::value;
127 struct HasOperatorEqual : HasOperatorEqualImpl<T>::type {};
128 template<
typename T1,
typename T2>
129 struct HasOperatorEqual<std::pair<T1, T2>>
131 static constexpr bool value = HasOperatorEqualImpl<T1>::value && HasOperatorEqualImpl<T2>::value;
134 template<
typename ValueType>
139 Holder(
const ValueType& value) :
144 Holder& operator=(
const Holder&) =
delete;
147 const std::type_info& getType()
const override
149 return typeid(ValueType);
152 Placeholder* clone()
const override
154 return new Holder(held);
157 bool compare(Placeholder* other)
const override
159 return compareImpl(other);
162 template<
typename T = ValueType>
163 typename std::enable_if<HasOperatorEqual<T>::value ==
true,
bool>::type compareImpl(Placeholder* other)
const
165 return getType() == other->getType() && held ==
static_cast<Holder*
>(other)->held;
168 template<
typename T = ValueType>
169 typename std::enable_if<HasOperatorEqual<T>::value ==
false,
bool>::type compareImpl(Placeholder* other)
const
171 MYGUI_EXCEPT(
"Type '" << getType().name() <<
"' is not comparable");
179 Placeholder* mContent;
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_EXCEPT(dest)
Any(const ValueType &value)
ValueType * castType(bool _throw=true) const