Horje
generate consecutive numbers at compile time Code Example
generate consecutive numbers at compile time
template<size_t n>
struct Elem{
    enum { res = 1 + Elem<n - 1>::res };
};

template<>
struct Elem<0> {
    enum { res = 0 };
};
template <size_t n, size_t...args>
struct A {
    static constexpr auto& array =
        A<n - 1, Elem<n>::res, args...>::array;
};
template <size_t...args>
struct A<0, args...> {
    static constexpr int array[] = { 0, args... };
};

template <size_t n>
static constexpr auto& Array = A<n>::array;

//пример использования
int main()
{   
    constexpr unsigned N = 8;
    for (unsigned n : Array<N>)
        cout << n << ' ';
    //0 1 2 3 4 5 6 7 8
}
generate consecutive numbers at compile time
template<size_t n>
struct Elem{
    enum { res = 1 + Elem<n - 1>::res };
};

template<>
struct Elem<0> {
    enum { res = 0 };
};
template <size_t n, size_t...args>
struct A {
    static constexpr auto& array =
        A<n - 1, Elem<n>::res, args...>::array;
};
template <size_t...args>
struct A<0, args...> {
    static constexpr int array[] = { 0, args... };
};

template <size_t n>
static constexpr auto& Array = A<n>::array;

//пример использования
int main()
{   
    constexpr unsigned N = 8;
    for (unsigned n : Array<N>)
        cout << n << ' ';
    //0 1 2 3 4 5 6 7 8
}




Cpp

Related
simplest code for stack implementation in c++ Code Example simplest code for stack implementation in c++ Code Example
hashset in cpp Code Example hashset in cpp Code Example
subsequence Code Example subsequence Code Example
c++ program to convert time in seconds to hours minutes and seconds Code Example c++ program to convert time in seconds to hours minutes and seconds Code Example
powershell script query mssql windows authentication Code Example powershell script query mssql windows authentication Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9