Namespaces
Variants
Views
Actions

std::any::operator=

From cppreference.com
< cpp‎ | utility‎ | any
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

Elementary string conversions
(C++17)
(C++17)
 
std::any
Member functions
any::operator=
Modifiers
Observers
Non-member functions
 
any& operator=( const any& rhs );
(1) (since C++17)
any& operator=( any&& rhs ) noexcept;
(2) (since C++17)
template<typename ValueType>
    any& operator=( ValueType&& rhs );
(3) (since C++17)

Assigns contents to the contained value.

1) Assigns by copying the state of rhs, as if by any(rhs).swap(*this).
2) Assigns by moving the state of rhs, as if by any(std::move(rhs)).swap(*this). rhs is left in a valid but unspecified state after the assignment.
3) Assigns the type and value of rhs, as if by any(std::forward<ValueType>(rhs)).swap(*this). This overload only participates in overload resolution if std::decay_t<ValueType> is not the same type as any and std::is_copy_constructible_v<std::decay_t<ValueType>> is true. .

Contents

[edit] Template parameters

ValueType - contained value type
Type requirements
-
std::decay_t<ValueType> must meet the requirements of CopyConstructible.

[edit] Parameters

rhs - object whose contained value to assign

[edit] Return value

*this

[edit] Exceptions

1,3) Throws bad_alloc or any exception thrown by the constructor of the contained type. If an exception is thrown, there are no effects (strong exception guarantee).

[edit] See also

constructs an any object
(public member function) [edit]