Namespaces
Variants
Views
Actions

std::pair<T1,T2>::operator=

From cppreference.com
< cpp‎ | utility‎ | pair
 
 
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::pair
Member functions
pair::operator=
Non-member functions
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
(C++11)
Deduction guides(C++17)
Helper classes
(C++11)
 
(1)
pair& operator=( const pair& other );
(until C++20)
constexpr pair& operator=( const pair& other );
(since C++20)
(2)
template< class U1, class U2 >
pair& operator=( const pair<U1,U2>& other );
(since C++11)
(until C++20)
template< class U1, class U2 >
constexpr pair& operator=( const pair<U1,U2>& other );
(since C++20)
(3)
pair& operator=( pair&& other ) noexcept(/* see below */);
(since C++11)
(until C++20)
constexpr pair& operator=( pair&& other ) noexcept(/* see below */);
(since C++20)
(4)
template< class U1, class U2 >
pair& operator=( pair<U1,U2>&& other );
(since C++11)
(until C++20)
template< class U1, class U2 >
constexpr pair& operator=( pair<U1,U2>&& other );
(since C++20)

Replaces the contents of the pair.

1) Copy assignment operator. Replaces the contents with a copy of the contents of other.
  • The assignment operator is implicitly declared. Using this assignment operator makes the program ill-formed if either first_type or second_type is a const-qualified type, or a reference type, or a class type with an inaccessible copy assignment operator, or an array type of such class.
(until C++11)
(since C++11)
2) Assigns other.first to first and other.second to second.
3) Move assignment operator. Replaces the contents with those of other using move semantics.
4) Assigns std::forward<U1>(p.first) to first and std::forward<U2>(p.second) to second.

Contents

[edit] Parameters

other - pair of values to replace the contents of this pair

[edit] Return value

*this

[edit] Exceptions

1-2) (none)
3)
noexcept specification:  
noexcept(

    std::is_nothrow_move_assignable<T1>::value &&
    std::is_nothrow_move_assignable<T2>::value

)
4) (none)

[edit] Example

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2729 C++11 pair::operator= was unconstrained and might
result in unnecessary undefined behavior
constrained

[edit] See also