--|---  
[ ` __cpp_lib_integer_sequence ` ](/w/cpp/feature_test#cpp_lib_integer_sequence "cpp/feature test") |  201304L  |  (C++14)  |  Compile-time integer sequences   
  
###  [ [ edit
](/mwiki/index.php?title=cpp/utility/integer_sequence&action=edit&section=8
"Edit section: Example") ]  Example

Note: see _Possible Implementation_ in [ ` std::apply `
](/w/cpp/utility/apply#Possible_implementation "cpp/utility/apply") for
another example.

Run this code

    
    
    #include <array>
    #include <cstddef>
    #include <iostream>
    #include <tuple>
    #include <utility>
     
    // debugging aid
    template<typename T, T... ints>
    void print_sequence(std::integer_sequence<T, ints...> int_seq)
    {
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "The sequence of size " << int_seq.size() << ": ";
        (([std::cout](http://en.cppreference.com/w/cpp/io/cout) << ints << ' '), ...);
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << '\n';
    }
     
    // convert array into a tuple
    template<typename Array, [std::size_t](http://en.cppreference.com/w/cpp/types/size_t)... I>
    auto a2t_impl(const Array& a, std::index_sequence<I...>)
    {
        return [std::make_tuple](http://en.cppreference.com/w/cpp/utility/tuple/make_tuple)(a[I]...);
    }
     
    template<typename T, [std::size_t](http://en.cppreference.com/w/cpp/types/size_t) N, typename Indices = std::make_index_sequence<N>>
    auto a2t(const [std::array](http://en.cppreference.com/w/cpp/container/array)<T, N>& a)
    {
        return a2t_impl(a, Indices{});
    }
     
    // pretty-print a tuple
    template<class Ch, class Tr, class Tuple, [std::size_t](http://en.cppreference.com/w/cpp/types/size_t)... Is>
    void print_tuple_impl([std::basic_ostream](http://en.cppreference.com/w/cpp/io/basic_ostream)<Ch, Tr>& os,
                          const Tuple& t,
                          std::index_sequence<Is...>)
    {
        ((os << (Is == 0? "" : ", ") << [std::get](http://en.cppreference.com/w/cpp/utility/variant/get)<Is>(t)), ...);
    }
     
    template<class Ch, class Tr, class... Args>
    auto& operator<<([std::basic_ostream](http://en.cppreference.com/w/cpp/io/basic_ostream)<Ch, Tr>& os,
                     const [std::tuple](http://en.cppreference.com/w/cpp/utility/tuple)<Args...>& t)
    {
        os << "(";
        print_tuple_impl(os, t, std::index_sequence_for<Args...>{});
        return os << ")";
    }
     
    int main()
    {
        print_sequence(std::integer_sequence<unsigned, 9, 2, 5, 1, 9, 1, 6>{});
        print_sequence(std::make_integer_sequence<int, 20>{});
        print_sequence(std::make_index_sequence<10>{});
        print_sequence(std::index_sequence_for<float, [std::iostream](http://en.cppreference.com/w/cpp/io/basic_iostream), char>{});
     
        [std::array](http://en.cppreference.com/w/cpp/container/array)<int, 4> array = {1, 2, 3, 4};
     
        // convert an array into a tuple
        auto tuple = a2t(array);
        static_assert([std::is_same_v](http://en.cppreference.com/w/cpp/types/is_same)<decltype(tuple),
                                     [std::tuple](http://en.cppreference.com/w/cpp/utility/tuple)<int, int, int, int>>, "");
     
        // print it to cout
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "The tuple: " << tuple << '\n';
    }

Output:

    
    
    The sequence of size 7: 9 2 5 1 9 1 6 
    The sequence of size 20: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
    The sequence of size 10: 0 1 2 3 4 5 6 7 8 9 
    The sequence of size 3: 0 1 2 
    The tuple: (1, 2, 3, 4)

###  [ [ edit
](/mwiki/index.php?title=cpp/utility/integer_sequence&action=edit&section=9
"Edit section: See also") ]  See also

[ to_array  ](/w/cpp/container/array/to_array "cpp/container/array/to array") (C++20)  |  creates a ` std::array ` object from a built-in array   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Tem