fork(1) download
  1. #include <iostream>
  2. #include <array>
  3.  
  4. using namespace std;
  5.  
  6. typedef size_t Data;
  7.  
  8. class MyFunction
  9. {
  10. private:
  11. static const std::array<std::string, 3> values;
  12. public:
  13. template<size_t N>
  14. static void Func(const Data& aData)
  15. {
  16. size_t index = (N > aData ? 2 : (N == aData ? 1 : 0) );
  17. cout << "Function::Func<"<< N << ">:\t" << N << values[index] << aData << endl;
  18. }
  19.  
  20. typedef decltype(&Func<0>) type;
  21. };
  22.  
  23. const std::array<std::string, 3> MyFunction::values {"<", "=", ">"};
  24.  
  25. template<class Function, size_t N>
  26. class FunctionManager
  27. {
  28. private:
  29. static const typename Function::type func_;
  30.  
  31. static constexpr typename Function::type Create()
  32. {
  33. return &Function::Func<N>;
  34. }
  35. public:
  36. void operator()(const Data &aData) const
  37. {
  38. func_(aData);
  39. }
  40. };
  41.  
  42. template<class Function, size_t N>
  43. const typename Function::type FunctionManager<Function, N>::func_ = FunctionManager<Function, N>::Create();
  44.  
  45. int main()
  46. {
  47. static const size_t N = 6;
  48. auto man = FunctionManager<MyFunction, N>();
  49. man(N/2);
  50. return 0;
  51. }
Compilation error #stdin compilation error #stdout 0s 3428KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static constexpr typename Function::type FunctionManager<Function, N>::Create()’:
prog.cpp:33:28: error: expected primary-expression before ‘;’ token
   return &Function::Func<N>;
                            ^
prog.cpp: In instantiation of ‘static constexpr typename Function::type FunctionManager<Function, N>::Create() [with Function = MyFunction; unsigned int N = 6u; typename Function::type = void (*)(const unsigned int&)]’:
prog.cpp:43:106:   required from ‘void (* const FunctionManager<MyFunction, 6u>::func_)(const Data&)’
prog.cpp:38:14:   required from ‘void FunctionManager<Function, N>::operator()(const Data&) const [with Function = MyFunction; unsigned int N = 6u; Data = unsigned int]’
prog.cpp:49:9:   required from here
prog.cpp:33:25: error: address of overloaded function with no contextual type information
   return &Function::Func<N>;
                         ^
prog.cpp:34:2: error: body of constexpr function ‘static constexpr typename Function::type FunctionManager<Function, N>::Create() [with Function = MyFunction; unsigned int N = 6u; typename Function::type = void (*)(const unsigned int&)]’ not a return-statement
  }
  ^
prog.cpp: In static member function ‘static constexpr typename Function::type FunctionManager<Function, N>::Create() [with Function = MyFunction; unsigned int N = 6u; typename Function::type = void (*)(const unsigned int&)]’:
prog.cpp:34:2: warning: control reaches end of non-void function [-Wreturn-type]
  }
  ^
stdout
Standard output is empty