fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class Hrm, class A>
  5. void foo(Hrm& h, A& a)
  6. {
  7. cout << "generic" << endl;
  8. }
  9.  
  10. template <template <bool> class Hrg>
  11. void foo(Hrg<false>& h, int& a)
  12. {
  13. cout << "specialized int" << endl;
  14. }
  15.  
  16. template <template <bool> class Hrg>
  17. void foo(Hrg<true>& h, const int& a)
  18. {
  19. cout << "specialized const-int" << endl;
  20. }
  21.  
  22. template <bool W>
  23. struct what;
  24.  
  25. template<> struct what<true> { };
  26. template<> struct what<false> { };
  27.  
  28.  
  29. int main() {
  30. what<true> wt;
  31. what<false> wf;
  32.  
  33. int i = 5;
  34. const int& ri = i;
  35.  
  36. foo(wt, i);
  37. foo(wf, i);
  38. foo(wt, ri);
  39. foo(wf, ri);
  40. return 0;
  41. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
generic
specialized int
specialized const-int
generic