std::get(std::array)(3)
β¨ NAME β¨
okay so bestie, this is the std::get(std::array)(3) page from the C++ Standard Libary β yes, thatβs how the header spells it, and weβre not fixing it. π
std::get(std::array) - std::get(std::array)
This is the tiny icon accessor that pulls the I^th element out of a std::array using the tuple-like interface. Itβs giving βsmall function, huge main character energy.β π
π Synopsis π
Defined in header <array>
template< std::size_t I, class T, std::size_t N > (1) (since C++11)
T& get( std::array<T,N>& a ) noexcept; (constexpr since C++14)
template< std::size_t I, class T, std::size_t N > (2) (since C++11)
T&& get( std::array<T,N>&& a ) noexcept; (constexpr since C++14)
template< std::size_t I, class T, std::size_t N > (3) (since C++11)
const T& get( const std::array<T,N>& a ) noexcept; (constexpr since C++14)
template< std::size_t I, class T, std::size_t N > (4) (since C++11)
const T&& get( const std::array<T,N>&& a ) noexcept; (constexpr since C++14)
It extracts the I^th element from the array using the tuple-like interface. No cap. The I must be an integer value in range [0, N). This is enforced at compile time as opposed to at() or operator[] β so yeah, the compiler is the bouncer here. πͺβ¨
πΈ Parameters πΈ
aβ array whose contents to extract
π«Ά Return value π«Ά
A reference to the I^th element of a.
β‘ Complexity β‘
Constant. Slay.
π Example π
The page says // Run this code, so bestie, run it:
#include <array>
#include <iostream>
constexpr std::array v{1, 2, 3};
static_assert(get<0>(v) == 1 && get<1>(v) == 2 && get<2>(v) == 3);
int main()
{
std::array<int, 3> a;
// set values:
get<0>(a) = 1, get<1>(a) = 2, get<2>(a) = 3;
// get values:
std::cout << '(' << get<0>(a) << ',' << get<1>(a) << ',' << get<2>(a) << ")\n";
}
π Output π
(1,2,3)
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 2485β Applied to: C++11 β Behavior as published: there are no overloads forconst array&&β Correct behavior: 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 (public member function)atβ access specified element with bounds checking (public member function)get(std::tuple)(C++11) β tuple accesses specified element (function template)get(std::pair)(C++11) β accesses an element of a pair (function template)get(std::variant)(C++17) β reads the value of the variant given the index or the type (if the type is unique), throws on error (function template)get(std::ranges::subrange)(C++20) β obtains iterator or sentinel from astd::ranges::subrange(function template)
this page came from http://cppreference.com on 2024.06.10, and itβs the std::get(std::array)(3) page. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms