fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <set>
  5. #include <valarray>
  6. #include <string>
  7.  
  8. template <template <typename ...> class P, typename ... Args>
  9. void f(const P<Args...> &p) { std::cout << sizeof...(Args) << " parameters! " << __PRETTY_FUNCTION__ << '\n'; }
  10.  
  11. template <template <typename ...> class P, typename ... Args>
  12. struct c
  13. {
  14. using type = P<Args...>;
  15. const std::size_t count = sizeof...(Args);
  16.  
  17. void f(const type &t) { std::cout << sizeof...(Args) << " parameters! " << __PRETTY_FUNCTION__ << '\n'; }
  18. };
  19.  
  20. template <template <typename, typename> class P, typename A, typename B>
  21. struct c<P, A, B>
  22. {
  23. using type = P<A, B>;
  24.  
  25. void f(const type &t) { std::cout << "Specialized --> " << __PRETTY_FUNCTION__ << '\n'; }
  26. };
  27.  
  28. int main()
  29. {
  30. f(std::valarray<int>{});
  31. f(std::pair<char, char>{});
  32. f(std::vector<double>{});
  33. f(std::set<float>{});
  34. f(std::map<int, int>{});
  35. std::cout << '\n';
  36. c<std::valarray, int> c_valarray_int;
  37. c<std::pair, int, char> c_pair_int_char;
  38. c<std::vector, int, std::allocator<int>> c_vector_int;
  39. c<std::map, int, int> c_map_int_int;
  40.  
  41. c_valarray_int.f({});
  42. c_pair_int_char.f({});
  43. c_vector_int.f({});
  44. c_map_int_int.f({});
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3100KB
stdin
Standard input is empty
stdout
1 parameters! void f(const P<Args ...>&) [with P = std::valarray; Args = {int}]
2 parameters! void f(const P<Args ...>&) [with P = std::pair; Args = {char, char}]
2 parameters! void f(const P<Args ...>&) [with P = std::vector; Args = {double, std::allocator<double>}]
3 parameters! void f(const P<Args ...>&) [with P = std::set; Args = {float, std::less<float>, std::allocator<float>}]
4 parameters! void f(const P<Args ...>&) [with P = std::map; Args = {int, int, std::less<int>, std::allocator<std::pair<const int, int> >}]

1 parameters! void c<P, Args>::f(const type&) [with P = std::valarray; Args = {int}; c<P, Args>::type = std::valarray<int>]
Specialized --> void c<P, A, B>::f(const type&) [with P = std::pair; A = int; B = char; c<P, A, B>::type = std::pair<int, char>]
Specialized --> void c<P, A, B>::f(const type&) [with P = std::vector; A = int; B = std::allocator<int>; c<P, A, B>::type = std::vector<int, std::allocator<int> >]
2 parameters! void c<P, Args>::f(const type&) [with P = std::map; Args = {int, int}; c<P, Args>::type = std::map<int, int>]