Namespaces
Variants
Views
Actions

std::get(std::array)

From cppreference.com
< cpp‎ | container‎ | array
Revision as of 21:13, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
template<size_t I, class T, size_t N >
T& get( array<T,N>& a );
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template<size_t I, class T, size_t N >
T&& get( array<T,N>&& a );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template<size_t I, class T, size_t N >
const T& get( const array<T,N>& a );
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Extracts the Ith element element from the array.

I must be an integer value in range [0, N). This is enforced at compile time as opposed to Template:rlpf or Template:rlpf.

Contents

Parameters

a - array whose contents to extract

Return value

1) Reference to the Ith element of a.

2) Rvalue reference to the Ith element of a, unless the element is of lvalue reference type, in which case lvalue reference is returned.

3) Const reference to the Ith element of a.

Exceptions

noexcept specification:  
noexcept
  

Example

#include <iostream>
#include <array>
 
int main()
{
    std::array<int, 3> arr;
 
    // set values:
    std::get<0>(arr) = 1;
    std::get<1>(arr) = 2;
    std::get<2>(arr) = 3;
 
    // get values:
    std::cout << "(" << std::get<0>(arr) << ", " << std::get<1>(arr)
              << ", " << std::get<2>(arr) << ")\n";
}

Output:

(1, 2, 3)

See also

Template:cpp/container/dcl list operator atTemplate:cpp/container/dcl list at
tuple accesses specified element
(function template) [edit]
accesses an element of a pair
(function template) [edit]