std::integer_sequence (3) - Linux Manuals
std::integer_sequence: std::integer_sequence
NAME
std::integer_sequence - std::integer_sequence
Synopsis
Defined in header <utility>
template< class T, T... Ints > (since C++14)
class integer_sequence;
The class template std::integer_sequence represents a compile-time sequence of integers. When used as an argument to a function_template, the parameter_pack Ints can be deduced and used in pack expansion.
Template parameters
T - an integer type to use for the elements of the sequence
...Ints - a non-type parameter pack representing the sequence
Member types
Member type Definition
value_type T
Member functions
size returns the number of elements in Ints
[static]
std::integer_sequence::size
static constexpr std::size_t size() noexcept;
Returns the number of elements in Ints. Equivalent to sizeof...(Ints)
Parameters
(none)
Return value
The number of elements in Ints.
Helper templates
A helper alias template std::index_sequence is defined for the common case where T is std::size_t.
template<std::size_t... Ints>
using index_sequence = std::integer_sequence<std::size_t, Ints...>;
A helper alias template std::make_integer_sequence is defined to simplify creation of std::integer_sequence and std::index_sequence types with 0, 1, 2, ..., N-1 as Ints:
template<class T, T N>
using make_integer_sequence = std::integer_sequence<T, /* a sequence 0, 1, 2, ..., N-1 */ >;
template<std::size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>;
The program is ill-formed if N is negative. If N is zero, the indicated type is integer_sequence<T>.
A helper alias template std::index_sequence_for is defined to convert any type parameter pack into an index sequence of the same length
template<class... T>
using index_sequence_for = std::make_index_sequence<sizeof...(T)>;
Example
Note: see Possible Implementation in std::apply for another example
// Run this code
Output: