fork download
  1. template<unsigned int...>
  2. struct IndexList{
  3. };
  4.  
  5. template<class IndexList, unsigned int LAST> struct Append;
  6.  
  7. template<unsigned int... FIRST, unsigned int LAST>
  8. struct Append<IndexList<FIRST...>, LAST> {
  9. typedef IndexList<FIRST..., LAST> Result;
  10. };
  11.  
  12. template<unsigned int N>
  13. struct Indices {
  14. typedef typename Append<typename Indices<N - 1U>::Result, N - 1U>::Result Result;
  15. };
  16.  
  17. template<>
  18. struct Indices<0U> {
  19. typedef IndexList<> Result;
  20. };
  21.  
  22. template<unsigned int N>
  23. struct PowerOfTen {
  24. static_assert(N < 20U, "Too large");
  25. static const unsigned long long value = 10ULL * PowerOfTen<N - 1>::value;
  26. };
  27.  
  28. template<>
  29. struct PowerOfTen<0U> {
  30. static const unsigned long long value = 1ULL;
  31. };
  32.  
  33. template<class IndexList> struct Values;
  34.  
  35. template<unsigned int... N>
  36. struct Values<IndexList<N...>> {
  37. static const unsigned long long values[sizeof...(N)];
  38. };
  39.  
  40. template<unsigned int... N>
  41. const unsigned long long Values<IndexList<N...>>::values[sizeof...(N)] = {
  42. PowerOfTen<N>::value...
  43. };
  44.  
  45. template<unsigned int N>
  46. using PowerOfTenTable = Values<typename Indices<N>::Result>;
  47.  
  48. #include <iostream>
  49.  
  50. int main() {
  51. for (unsigned int i = 0; i < 10U; ++i) {
  52. std::cout << PowerOfTenTable<10U>::values[i] << std::endl;
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
1
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000