std::get(std::integer_sequence)
From cppreference.com
| Defined in header <utility>
|
||
template< std::size_t I, class T, T... Values >
constexpr T get( std::integer_sequence<T, Values...> ) noexcept;
|
(since C++26) | |
Extracts the Ith element from the integer sequence.
If I is not less than sizeof...(Values), the program is ill-formed.
Return value
Values...[I]
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_integer_sequence |
202511L |
(C++26) | Tuple protocol for std::integer_sequence
|
Example
Run this code
#include <utility>
int main()
{
constexpr auto seq{std::integer_sequence<int, 11, 22, 33, 44, 0o0>{}};
static_assert(std::get<0>(seq) == 11);
static_assert(std::get<2>(seq) == 33);
// In C++26 structured bindings for std::integer_sequence
// also works, due to support of the full tuple protocol:
constexpr auto [_, b, _, d, _] = seq;
static_assert(b == 22 and d == 44);
}
See also
| Structured binding (C++17) | binds the specified names to sub-objects or tuple elements of the initializer |
obtains the size of an integer_sequence (class template specialization) | |
obtains the type of the elements of integer_sequence (class template specialization) |
(C++11) |
accesses an element of an array (function template) |
(C++11) |
accesses an element of a pair (function template) |
(C++11) |
tuple accesses specified element (function template) |
(C++17) |
reads the value of the variant given the index or the type (if the type is unique), throws on error (function template) |
(C++20) |
obtains iterator or sentinel from a std::ranges::subrange (function template) |
(C++26) |
obtains a reference to real or imaginary part from a std::complex (function template) |