fork download
  1. #include <iostream>
  2.  
  3. template <typename...>
  4. struct wrapper
  5. {
  6. static void foo() {
  7. std::cout << "generic" << std::endl;
  8. }
  9. };
  10.  
  11. template<typename T>
  12. struct wrapper<T>
  13. {
  14. static void foo() {
  15. std::cout << "one argument" << std::endl;
  16. }
  17. };
  18.  
  19. // just an illustration
  20. template <typename T> // <--------------------------------------------------+
  21. struct wrapper <int, double, T> // <--- to instantiate, use this list of arguments |
  22. { // not this one -----------------------------+
  23. // that is, say `wrapper<int, double, sometype>`
  24. static void foo() {
  25. std::cout << "three arguments (int, double, something)" << std::endl;
  26. }
  27. };
  28.  
  29. template <template<typename ...> class T, // <-----------------------------------------+
  30. typename K> // |
  31. struct wrapper<T<K>> // <--- to instantiate, use this list of arguments |
  32. { // not this one ------------------------------+
  33. // that is, say `wrapper<sometemplate<sometype>>`
  34. static void foo() {
  35. std::cout << "the template thingy" << std::endl;
  36. }
  37. };
  38.  
  39. template <typename> class X {};
  40.  
  41. int main ()
  42. {
  43. wrapper<int, int>::foo();
  44. wrapper<int>::foo();
  45. wrapper<int, double, X<int>>::foo();
  46. wrapper<X<int>>::foo();
  47. }
  48.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
generic
one argument
three arguments (int, double, something)
the template thingy