Namespaces
Variants

std::tuple_element<std::integer_sequence>

From cppreference.com
Defined in header <utility>
template< std::size_t I, class T, T... Values >
struct tuple_element< I, std::integer_sequence<T, Values...> >;
(1) (since C++26)
template< std::size_t I, class T, T... Values >
struct tuple_element< I, const std::integer_sequence<T, Values...> >;
(2) (since C++26)

Provides compile-time access to the type of the Ith element (which is always T) in an std::integer_sequence.

If I is not less than sizeof...(Values), the program is ill-formed.

Nested types

Name Definition
type T

Possible implementation

template<std::size_t I, class T>
struct tuple_element;

template<std::size_t I, class T, T... Values> requires (I < sizeof...(Values))
struct tuple_element<I, std::integer_sequence<T, Values...>>
{
    using type = T;
};

template<std::size_t I, class T, T... Values> requires (I < sizeof...(Values))
struct tuple_element<I, const std::integer_sequence<T, Values...>>
{
    using type = T;
};

Example

#include <tuple>
#include <type_traits>
#include <utility>

int main()
{
    using Seq = std::integer_sequence<int, 11, 22, 33>;

    static_assert(std::is_same_v<std::tuple_element_t<1, Seq>, int>);

    // In C++26 structured bindings for std::integer_sequence
    // also works, due to support of the full tuple protocol:
    constexpr Seq seq{};
    constexpr auto [first, second, third] = seq;
    static_assert(first == 11 and second == 22 and third == 33);
}

See also

Structured binding (C++17) binds the specified names to sub-objects or tuple elements of the initializer[edit]
accesses an element of an integer_sequence
(function template) [edit]
obtains the size of an integer_sequence
(class template specialization) [edit]
obtains the element types of a tuple-like type
(class template) [edit]
obtains a reflection of element types of the tuple-like type
(function) [edit]
obtains the type of the elements of array
(class template specialization) [edit]
obtains the type of the elements of pair
(class template specialization) [edit]
obtains the type of the specified element
(class template specialization) [edit]
obtains the type of the iterator or the sentinel of a std::ranges::subrange
(class template specialization) [edit]
obtains the underlying real and imaginary number type of a std::complex
(class template specialization) [edit]