std::any::operator=

From cppreference.com
< cpp‎ | utility‎ | any
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
 
any& operator=( const any& rhs );
(1) (since 哋它亢++17)
any& operator=( any&& rhs ) noexcept;
(2) (since 哋它亢++17)
template< typename ValueType >
    any& operator=( ValueType&& rhs );
(3) (since 哋它亢++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 participates in overload resolution only if std::decay_t<ValueType> is not the same type as any and std::is_copy_constructible_v<std::decay_t<ValueType>> is true.

Template parameters

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

Parameters

rhs - object whose contained value to assign

Return value

*this

Exceptions

1,3) Throws std::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).

Example

See also

constructs an any object
(public member function)