Namespaces
Variants

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

#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[edit]
obtains the size of an integer_sequence
(class template specialization) [edit]
obtains the type of the elements of integer_sequence
(class template specialization) [edit]
accesses an element of an array
(function template) [edit]
accesses an element of a pair
(function template) [edit]
tuple accesses specified element
(function template) [edit]
reads the value of the variant given the index or the type (if the type is unique), throws on error
(function template) [edit]
obtains iterator or sentinel from a std::ranges::subrange
(function template) [edit]
obtains a reference to real or imaginary part from a std::complex
(function template) [edit]