A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/tuple/tuple/operator=/ below:

public member function

<tuple>

std::tuple::operator= copy / move (1)
tuple& operator= (const tuple&  tpl);tuple& operator= (      tuple&& tpl) noexcept( /* see below */ );
implicit conversion (2)
template <class... UTypes>  tuple& operator= (const tuple<UTypes...>&  tpl);template <class... UTypes>  tuple& operator= (      tuple<UTypes...>&& tpl);
conversion from pair (3)
template <class U1, class U2>  tuple& operator= (const pair<U1,U2>&  pr);template <class U1, class U2>  tuple& operator= (      pair<U1,U2>&& pr);

Assign content

Assigns tpl (or pr) as the new content for the tuple object.

Each of the elements in the tuple object is assigned its corresponding element of tpl (or pr).

The forms taking an lvalue reference as argument perform copy assignments, with the elements of its argument preserving their values after the call. The forms taking an rvalue reference perform move assignments (as if calling forward for each element), which, for elements of types supporting move semantics implies that these elements of tpl (or pr) are left in an unspecified but valid state.

The move assignment (1, second signature) is only noexcept if all of the types in the tuple are nothrow move-assignable.



Parameters
tpl
Another tuple object with the same number of elements.
This may be an object of the same type as the object being constructed (version 2) or of a tuple type whose elements' types are implicitly convertible to those in the tuple object being constructed.
pr
A pair object whose first and second types (U1 and U2) match those used as class template arguments, or are implicitly convertible to them.

Return value*this
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// tuple assignments
#include <iostream>     // std::cout
#include <utility>      // std::pair
#include <tuple>        // std::tuple, std::make_tuple, std::get

int main ()
{
  std::pair<int,char> mypair (0,' ');

  std::tuple<int,char> a (10,'x');
  std::tuple<long,char> b, c;

  b = a;                                // copy assignment
  c = std::make_tuple (100L,'Y');       // move assignment
  a = c;                                // conversion assignment
  c = std::make_tuple (100,'z');        // conversion / move assignment
  a = mypair;                           // from pair assignment
  a = std::make_pair (2,'b');           // form pair /move assignment

  std::cout << "c contains: " << std::get<0>(c);
  std::cout << " and " << std::get<1>(c) << '\n';

  return 0;
}
Output:

Data races All copied elements are accessed.
The object and all its elements are modified.
The forms taking an rvalue reference as argument also modify tpl (or pr) if any of its component types support move semantics for this assignment.


Exception safety If none of the individual assignment operations performed on the members of tuple can throw, the function never throws exceptions (no-throw guarantee).
Otherwise, if any of the forms taking an rvalue reference as argument is called, and at least one of the types in the tuple can be assigned with move semantics, the operation may leave either or both objects involved in the operation in an invalid state in case of exception (no guarantee).
Otherwise, the operation guarantees that both objects involved in the operation end up in a valid state in case of exception (basic guarantee).

See also
tuple::tuple
Construct tuple (public member function)
make_tuple
Construct tuple (function template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4