Go to the documentation of this file.
59 #include <type_traits>
113 other.content =
nullptr;
124 template<
typename ValueType>
125 any(
const ValueType& value) :
126 content(new
holder<typename std::remove_cv<typename std::decay<const ValueType>::
type>::
type>(value))
137 template<
typename ValueType>
138 any(ValueType&& value,
typename std::enable_if<!std::is_same<any&, ValueType>::value>::
type* =
nullptr,
typename std::enable_if<!std::is_const<ValueType>::value>::
type* =
nullptr) :
139 content(new
holder<typename std::decay<ValueType>::
type>(static_cast<ValueType&&>(value)))
154 any(rhs).swap(*
this);
191 template <
class ValueType>
194 any(
static_cast<ValueType&&
>(rhs)).swap(*
this);
246 const std::type_info&
type() const noexcept
260 virtual const std::type_info&
type() const noexcept = 0;
268 template<typename ValueType>
278 held(static_cast<ValueType&&>(value))
282 virtual const std::type_info&
type() const noexcept
284 return typeid(ValueType);
303 template<
typename ValueType>
336 virtual const char*
what() const noexcept
override
338 return "bad any_cast";
351 template<
typename ValueType>
366 template<
typename ValueType>
369 return any_cast<ValueType>(
const_cast<any*
>(operand));
381 template<
typename ValueType>
384 typedef typename std::remove_reference<ValueType>::type nonref;
386 nonref* result = any_cast<nonref>(std::addressof(operand));
390 typedef typename std::conditional<std::is_reference<ValueType>::value, ValueType,
typename std::add_lvalue_reference<ValueType>::type>
::type ref_type;
392 return static_cast<ref_type
>(*result);
404 template<
typename ValueType>
407 typedef typename std::remove_reference<ValueType>::type nonref;
409 return any_cast<const nonref&>(
const_cast<any&
>(operand));
421 template<
typename ValueType>
424 static_assert(std::is_rvalue_reference<ValueType&&>::value || std::is_const<
typename std::remove_reference<ValueType>::type>::value,
"any_cast shall not be used for getting nonconst references to temporary objects");
426 return any_cast<ValueType>(operand);
bool has_value() const noexcept
Checks whether the object contains a value.
const std::type_info & type() const noexcept
Queries the contained type.
any(const any &other)
Copies content of other into a new instance, so that any content is equivalent in both type and value...
void swap(any &lhs, any &rhs) noexcept
Overloads the std::swap algorithm for std::any.
virtual placeholder * clone() const
Port of boost::any for C++11 compilers.
any(any &&other) noexcept
Moves content of other into a new instance, so that any content is equivalent in both type and value ...
any(const ValueType &value)
Constructs an object with initial content an object of type std::decay_t<ValueType>,...
Defines a type of object to be thrown by the value-returning forms of blf::any::any_cast on failure.
any & operator=(ValueType &&rhs)
Assigns contents to the contained value.
any & operator=(any &&rhs) noexcept
Assigns contents to the contained value.
holder(const ValueType &value)
any & operator=(const any &rhs)
Assigns contents to the contained value.
void reset() noexcept
If not empty, destroys the contained object.
any(ValueType &&value, typename std::enable_if<!std::is_same< any &, ValueType >::value >::type *=nullptr, typename std::enable_if<!std::is_const< ValueType >::value >::type *=nullptr)
Constructs an object with initial content an object of type std::decay_t<ValueType>,...
virtual const std::type_info & type() const noexcept=0
any() noexcept
Constructs an empty object.
virtual placeholder * clone() const =0
friend ValueType * any_cast(any *operand) noexcept
Performs type-safe access to the contained object.
any & swap(any &rhs) noexcept
Swaps the content of two any objects.
virtual const std::type_info & type() const noexcept
holder(ValueType &&value)
The class any describes a type-safe container for single values of any type.
~any() noexcept
Destruct the object.
virtual const char * what() const noexcept override
Returns the explanatory string.