fork download
  1. #include <iostream>
  2. #include <array>
  3.  
  4. using uu = std::size_t;
  5.  
  6. template< uu... ns > struct seq{};
  7.  
  8. template< uu from = 0 >
  9. struct index_from
  10. {
  11. template< uu n, uu... ns > struct end : end< n - 1, n - 1, ns... > {};
  12. template< uu... ns > struct end< from, ns... > : seq< ns... > {};
  13. template< uu last > struct to : end< last + 1 > {};
  14. };
  15.  
  16. template< uu... ns >
  17. constexpr auto make_index_array( seq< ns... > )
  18. {
  19. return std::array< uu, sizeof...( ns ) > { { ns... } };
  20. }
  21.  
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. auto arr = make_index_array( index_from< 10 >::to< 15 >{} );
  27. for( const auto v : arr )
  28. cout << v << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
10
11
12
13
14
15