92 content(other.content ? other.content->clone() : 0)
102 content(other.content)
113 template<
typename ValueType>
114 any(
const ValueType& value) :
115 content(new holder<typename std::remove_cv<typename std::decay<const ValueType>::
type>::
type>(value))
124 template<
typename ValueType>
125 any(ValueType&& value,
typename std::enable_if<!std::is_same<any&, ValueType>::value>
::type* = 0,
typename std::enable_if<!std::is_const<ValueType>::value>
::type* = 0) :
126 content(new holder<typename std::decay<ValueType>::
type>(static_cast<ValueType&&>(value)))
147 any(rhs).swap(*
this);
175 template <
class ValueType>
178 any(
static_cast<ValueType&&
>(rhs)).swap(*
this);
199 std::swap(content, rhs.content);
219 const std::type_info&
type() const noexcept
221 return content ? content->type() :
typeid(void);
229 virtual ~placeholder()
233 virtual const std::type_info& type() const noexcept = 0;
235 virtual placeholder* clone() const = 0;
240 template<typename ValueType>
241 class holder : public placeholder
244 holder(
const ValueType& value) :
249 holder(ValueType&& value) :
250 held(static_cast<ValueType&&>(value))
254 virtual const std::type_info& type() const noexcept
256 return typeid(ValueType);
260 virtual placeholder* clone()
const
262 return new holder(held);
274 template<
typename ValueType>
277 placeholder* content;
306 virtual const char*
what() const noexcept
override
308 return "bad any_cast";
321template<
typename ValueType>
324 return operand && operand->type() ==
typeid(ValueType) ? std::addressof(
static_cast<any::holder<typename std::remove_cv<ValueType>::type
>*>(operand->content)->held) : 0;
336template<
typename ValueType>
337inline const ValueType*
any_cast(
const any* operand)
noexcept
339 return any_cast<ValueType>(
const_cast<any*
>(operand));
351template<
typename ValueType>
354 typedef typename std::remove_reference<ValueType>::type nonref;
356 nonref* result = any_cast<nonref>(std::addressof(operand));
358 throw bad_any_cast();
360 typedef typename std::conditional<std::is_reference<ValueType>::value, ValueType,
typename std::add_lvalue_reference<ValueType>::type>
::type ref_type;
362 return static_cast<ref_type
>(*result);
374template<
typename ValueType>
377 typedef typename std::remove_reference<ValueType>::type nonref;
378 return any_cast<const nonref&>(
const_cast<any&
>(operand));
390template<
typename ValueType>
393 static_assert(std::is_rvalue_reference<ValueType&&>::value || std::is_const<typename std::remove_reference<ValueType>::type>::value,
394 "any_cast shall not be used for getting nonconst references to temporary objects");
396 return any_cast<ValueType>(operand);
any(any &&other) noexcept
any & operator=(ValueType &&rhs)
any(const ValueType &value)
friend ValueType * any_cast(any *) noexcept
any & operator=(any &&rhs) noexcept
any & operator=(const any &rhs)
any(ValueType &&value, typename std::enable_if<!std::is_same< any &, ValueType >::value >::type *=0, typename std::enable_if<!std::is_const< ValueType >::value >::type *=0)
bool has_value() const noexcept
any & swap(any &rhs) noexcept
const std::type_info & type() const noexcept
virtual const char * what() const noexcept override