23 General utilities library [utilities]
23.8 Storage for any type [any]
constexpr any() noexcept;
Postconditions:
has_value() is
false. any(const any& other);
Effects:
If
other.has_value() is
false, constructs an object that has no value
. Otherwise, equivalent to
any(in_place<T>, any_cast<const T&>(other))
where
T is the type of the contained object
.Throws:
Any exceptions arising from calling the selected constructor for the contained value
. any(any&& other) noexcept;
Effects:
If
other.has_value() is
false, constructs an object that has no value
. Otherwise, constructs an object of type
any that
contains either the contained object of
other, or
contains an object of the same type constructed from
the contained object of
other considering that contained object as an rvalue
.Postconditions:
other is left in a valid but otherwise unspecified state
. template<class T>
any(T&& value);
Requires:
VT shall satisfy the
CopyConstructible requirements
. Effects:
Constructs an object of type
any that contains an object of type
VT direct-initialized with
std::forward<T>(value). Remarks:
This constructor shall not participate in overload resolution unless
VT is not the same type as
any,
VT is not a specialization of
in_place_type_t,
and
is_copy_constructible_v<VT> is
true. Throws:
Any exception thrown by the selected constructor of
VT. template <class T, class... Args>
explicit any(in_place_type_t<T>, Args&&... args);
Requires: VT shall satisfy the
CopyConstructible requirements
. Effects: Initializes the contained value as if direct-non-list-initializing an object of
type
VT with the arguments
std::forward<Args>(args).... Postconditions: *this contains a value of type
VT. Throws: Any exception thrown by the selected constructor of
VT. Remarks:
This constructor shall not participate in overload resolution unless
is_copy_constructible_v<VT> is
true and
is_constructible_v<VT, Args...> is
true. template <class T, class U, class... Args>
explicit any(in_place_type_t<T>, initializer_list<U> il, Args&&... args);
Requires: VT shall satisfy the
CopyConstructible requirements
. Effects: Initializes the contained value as if direct-non-list-initializing an object of
type
VT with the arguments
il, std::forward<Args>(args).... Postconditions: *this contains a value
. Throws: Any exception thrown by the selected constructor of
VT. Remarks:
This constructor shall not participate in overload resolution unless
is_copy_constructible_v<VT> is
true and
is_constructible_v<VT, initializer_list<U>&, Args...> is
true. ~any();
Effects:
As if by
reset().