table of contents
std::get(std::array)(3) | C++ Standard Libary | std::get(std::array)(3) |
NAME¶
std::get(std::array) - std::get(std::array)
Synopsis¶
Defined in header <array>
template< std::size_t I, class T, (since
std::size_t N > C++11)
T& get( std::array<T,N>& a ) noexcept; (until
C++14)
template< std::size_t I, class T,
std::size_t N > (since
constexpr T& get( std::array<T,N>& a ) C++14)
noexcept;
template< std::size_t I, class T, (since
std::size_t N > C++11)
T&& get( std::array<T,N>&& a ) noexcept; (until
C++14)
template< std::size_t I, class T,
std::size_t N > (since
constexpr T&& get( std::array<T,N>&& a ) C++14)
noexcept; (1)
template< std::size_t I, class T, (since
std::size_t N > C++11)
const T& get( const std::array<T,N>& a ) (until
noexcept; (2) C++14)
template< std::size_t I, class T,
std::size_t N > (since
constexpr const T& get( const C++14)
std::array<T,N>& a ) noexcept; (3)
template< std::size_t I, class T, (since
std::size_t N > C++11)
const T&& get( const std::array<T,N>&& a ) (until
noexcept; (4) C++14)
template< std::size_t I, class T,
std::size_t N > (since
constexpr const T&& get( const C++14)
std::array<T,N>&& a ) noexcept;
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[].
Parameters¶
a - array whose contents to extract
Return value¶
A reference to the Ith element of a.
Complexity¶
Constant.
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)
Defect reports
The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG 2485 C++11 there are no overloads for const array&& the overloads
are added
See also¶
Structured binding (C++17) binds the specified names to
sub-objects or tuple
elements of the initializer
operator[] access specified element
(C++11) (public member function)
at access specified element with bounds checking
(C++11) (public member function)
std::get(std::tuple) tuple accesses specified element
(C++11) (function template)
std::get(std::pair) accesses an element of a pair
(C++11) (function template)
std::get(std::variant) reads the value of the variant given the index or the
(C++17) type (if the type is unique), throws on error
(function template)
get(std::ranges::subrange) obtains iterator or sentinel from a
std::ranges::subrange
(C++20) (function template)
2022.07.31 | http://cppreference.com |