C++ Tuple Library - get


Advertisements

Description

It returns a reference to the Ith element of tuple tpl.

Declaration

Following is the declaration for std::get.

C++98

	
template <size_t I, class... Types>

C++11

template <size_t I, class... Types>

C++14

template <size_t I, class... Types>

Parameters

  • I − It contains the position of element.

  • Types − It contains the information about type of element in tuple.

Return Value

It returns a reference to the Ith element of tuple tpl.

Exceptions

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

Data races

None introduced by this call.

Example

In below example for std::get.

#include <iostream>
#include <tuple>

int main () {
   std::tuple<int,char> mytuple (100,'x');

   std::get<0>(mytuple) = 200;

   std::cout << "tuple contains: ";
   std::cout << std::get<0>(mytuple) << " and " << std::get<1>(mytuple);
   std::cout << std::endl;

   return 0;
}

The output should be like this −

tuple contains: 200 and x
tuple.htm
Advertisements