fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <functional>
  4.  
  5. // initial declaration
  6. template <typename... T> struct X;
  7.  
  8. // default (does nothing)
  9. template<> struct X<>
  10. {
  11. };
  12.  
  13. // initial type and zero-or-more following types
  14. template <typename H, typename... T>
  15. struct X<H*, T...> : public X<T...>
  16. {
  17. H* value;
  18. X(H* value, T... args)
  19. : value(value), X<T...>(args...)
  20. {
  21. }
  22. };
  23.  
  24. template <typename H, typename... T>
  25. std::ostream& operator<<(std::ostream& stream, X<H*,T...> const & x)
  26. {
  27. return stream << "specialized scalar pointer";
  28. }
  29.  
  30. template <typename V, typename... T>
  31. std::ostream& operator<<(std::ostream& stream, X<std::vector<V*>*, T...> const & x)
  32. {
  33. return stream << "specialized vector pointer";
  34. }
  35.  
  36. int main()
  37. {
  38. double a,b;
  39. X<double*,double*> x (&a,&b);
  40.  
  41. std::vector<double *> v;
  42. X<std::vector<double*>*, double*> y (&v, &b);
  43.  
  44. std::cout << x << std::endl;
  45. std::cout << y << std::endl;
  46. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
specialized scalar pointer
specialized vector pointer