std::get(std::array) - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::get(std::array)

From cppreference.com
< cpp‎ | container‎ | array

template< size_t I, class T, size_t N > constexpr T& get( array<T,N>& a ); | (1) | (since C++11)
template< size_t I, class T, size_t N > constexpr T&& get( array<T,N>&& a ); | (2) | (since C++11)
template< size_t I, class T, size_t N > constexpr const T& get( const array<T,N>& a ); | (3) | (since C++11)
template< size_t I, class T, size_t N > constexpr const T&& get( const array<T,N>&& a ); | (4) | (since C++17)

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 at() or operator[].

### [edit] Parameters

a | - | array whose contents to extract

### [edit] Return value

A reference to the `Ith` element of `a`.

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Notes

The overloads are marked as constexpr since C++14.

### [edit] Example

Run this code

    #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)

### [edit] See also

operator[] | access specified element (public member function) [edit]
at | access specified element with bounds checking (public member function) [edit]
std::get(std::tuple) | tuple accesses specified element (function template) [edit]
std::get(std::pair) (C++11) | accesses an element of a `pair` (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/container/array/get&oldid=81564"
Category:

- unconditionally noexcept