Namespaces
Variants

std::make_integer_sequence, std::make_index_sequence, std::index_sequence_for

From cppreference.com
Defined in header <utility>
template< class T, T N >
using make_integer_sequence = std::integer_sequence<T, /* see below */>;
(1) (since C++14)
template< std::size_t N >
using make_index_sequence = std::make_integer_sequence<std::size_t, N>;
(2) (since C++14)
template< class... T >
using index_sequence_for = std::make_index_sequence<sizeof...(T)>;
(3) (since C++14)
1) The alias template std::make_integer_sequence represents a compile-time sequence of N values of type T.
  • If N is positive, the sequence increments from zero to N - 1.
  • If N is zero, the sequence is empty (equivalent to std::integer_sequence<T> in this case).
If N is negative, the program is ill-formed.
2) The std::index_sequence version of std::make_integer_sequence.
3) A variant of std::make_index_sequence taking a type parameter pack.

Example

#include <iostream>
#include <string_view>
#include <utility>

template <typename T, T... Ints>
void print_sequence(const std::string_view rem, const std::integer_sequence<T, Ints...>)
{
    std::cout << rem;
    ((std::cout << Ints << ' '), ...);
    std::cout << '\n';
}

int main()
{
    print_sequence("make_integer_sequence<int, 5>: ", std::make_integer_sequence<int, 5>{});
    print_sequence("make_index_sequence<4>:        ", std::make_index_sequence<4>{});
    [rem = "index_sequence_for (3 args):   "]<typename... Args>(Args...)
    {
        print_sequence(rem, std::index_sequence_for<Args...>{});
    }
    ("hello", 42, 3.14);
}

Output:

make_integer_sequence<int, 5>: 0 1 2 3 4 
make_index_sequence<4>:        0 1 2 3 
index_sequence_for (3 args):   0 1 2

See also

compile-time sequence of std::size_t
(alias template)[edit]
(C++17)
calls a function with a tuple of arguments
(function template) [edit]
construct an object with a tuple of arguments
(function template) [edit]