fork download
  1. #include <cstddef>
  2.  
  3. template<size_t n>
  4. struct counterNumber {
  5. char data[n+1];
  6. };
  7.  
  8. template<size_t index, size_t val>
  9. counterNumber<val> magic(counterNumber<index>, counterNumber<val>);
  10.  
  11. #define COUNTER_READ() \
  12.   (sizeof( \
  13.   magic(counterNumber<1>(), \
  14.   magic(counterNumber<2>(), \
  15.   magic(counterNumber<4>(), \
  16.   magic(counterNumber<8>(), \
  17.   magic(counterNumber<16>(), \
  18.   magic(counterNumber<32>(), \
  19.   magic(counterNumber<64>(), \
  20.   magic(counterNumber<128>(), counterNumber<0>())))))))))-1)
  21.  
  22. #define COUNTER_INC() \
  23.   counterNumber<COUNTER_READ()+1> magic( \
  24.   counterNumber<(COUNTER_READ()+1)&~COUNTER_READ()>, \
  25.   counterNumber<(COUNTER_READ()+1)&COUNTER_READ()>)
  26.  
  27. #include <iostream>
  28. using namespace std;
  29. #define TO_STRING(x) #x
  30.  
  31.  
  32. #define REG_FUNCTIONAL(headFunction) \
  33.   template<> \
  34.   constexpr auto foo< COUNTER_READ() >() \
  35.   { \
  36.   return TO_STRING(headFunction); \
  37.   } \
  38.   COUNTER_INC(); \
  39.   headFunction
  40.  
  41. template<size_t n>
  42. constexpr auto foo(void){return "";}
  43.  
  44.  
  45. REG_FUNCTIONAL(void function(int a)){(void)a;}
  46. REG_FUNCTIONAL(void function1(int a)){(void)a;}
  47.  
  48.  
  49. // your code goes here
  50. template<size_t n>
  51. std::string callFoo()
  52. {
  53. return std::string(foo<n>())+callFoo<n-1>();
  54. }
  55.  
  56. template<>
  57. std::string callFoo<0>()
  58. {
  59. return std::string(foo<0>());
  60. }
  61.  
  62. int main() {
  63. std::cout<<callFoo<COUNTER_READ()-1>();
  64. return 0;
  65. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
void function1(int a)void function(int a)