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
Run this code
#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 |
(C++26) |
accesses an element of an integer_sequence (function template) |
obtains the size of an integer_sequence (class template specialization) |
(C++11) |
obtains the element types of a tuple-like type (class template) |
(C++26) |
obtains a reflection of element types of the tuple-like type (function) |
obtains the type of the elements of array (class template specialization) | |
obtains the type of the elements of pair (class template specialization) | |
| obtains the type of the specified element (class template specialization) | |
| obtains the type of the iterator or the sentinel of a std::ranges::subrange (class template specialization) | |
| obtains the underlying real and imaginary number type of a std::complex (class template specialization) |