C++ Tuple Library - operator=



Description

It is a tuple operator and assigns tpl (or pr) as the new content for the tuple object.

Declaration

Following is the declaration for std::tuple::operator=

C++98

	
tuple& operator= (const tuple&  tpl);
tuple& operator= (      tuple&& tpl) noexcept

C++11

tuple& operator= (const tuple&  tpl);
tuple& operator= (      tuple&& tpl) noexcept

Parameters

  • tpl − It is a another tuple object with same number of elements.

  • pr − it has pair of objects.

Return Value

none

Exceptions

No-throw guarantee − this member function never throws exceptions.

Data races

All copied elements are accessed.

Example

In below example for std::tuple::operator=.

#include <iostream>
#include <utility>
#include <tuple>

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

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

   b = a;
   c = std::make_tuple (100L,'Y');
   a = c;
   c = std::make_tuple (100,'z');
   a = mypair;
   a = std::make_pair (2,'b');

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

   return 0;
}

The output should be like this −

a contains: 2 and b
tuple.htm
Advertisements