fork(1) download
  1. // StackOverflow.cpp : Defines the entry point for the console application.
  2. //
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. template<typename T, class CONT>
  10. struct foo_policy
  11. {
  12. static inline void execute() {
  13. cout << "regular foo: \n" ;
  14. }
  15. };
  16.  
  17. template<typename T>
  18. struct foo_policy<T, std::vector<T*>>
  19. {
  20. static inline void execute() {
  21. cout << "specialized foo: \n" ;
  22. }
  23. };
  24.  
  25.  
  26.  
  27. template<class T , class CONT >
  28. class Container
  29. {
  30. private:
  31. CONT container;
  32. T someData;
  33. public:
  34. void foo()
  35. {
  36. foo_policy<T,CONT>::execute();
  37. }
  38. };
  39.  
  40.  
  41.  
  42. int main()
  43. {
  44. Container<int, std::vector<int>> a;
  45. Container<int, std::vector<int*>> b;
  46.  
  47. a.foo();
  48. b.foo();
  49.  
  50. // your code goes here
  51. return 0;
  52. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
regular foo: 
specialized foo: