fork download
  1. #include <iostream>
  2.  
  3.  
  4. template<typename ... AA>
  5. using hfX = void(*)(AA ... );
  6.  
  7. void hf1 (int a)
  8. { std::cout<< "hf1"<<std::endl; }
  9.  
  10. void hf2 (int a, int i)
  11. { std::cout<< "hf2 "<<i<<std::endl;}
  12.  
  13. template <typename Tf, Tf F>
  14. class Collection;
  15.  
  16. template <typename ... I, hfX<I...> F>
  17. class Collection<hfX<I...>, F>
  18. {
  19. public:
  20. int i_=56;
  21.  
  22. template <std::size_t N = sizeof...(I)>
  23. typename std::enable_if<N == 1U, void>::type test ()
  24. {
  25. F(0);
  26. }
  27.  
  28. template <std::size_t N = sizeof...(I)>
  29. typename std::enable_if<N == 2U, void>::type test ()
  30. {
  31. F(0,i_+1);
  32. }
  33. };
  34.  
  35. int main ()
  36. {
  37. Collection<hfX<int>, hf1> c1;
  38. Collection<hfX<int,int>, hf2> c2;
  39.  
  40. c1.test(); // print "hf1"
  41. c2.test(); // print "hf2 57"
  42. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
hf1
hf2 57