fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. template<class T, int N>
  7. constexpr int Val = 3;
  8.  
  9. template<>
  10. constexpr int Val<int,0> = 5;
  11.  
  12.  
  13. template<int N>
  14. constexpr int Val<char,N> = N;
  15.  
  16.  
  17. template<class T, int N, int M = Val<T,N>>
  18. class Test
  19. {
  20. public:
  21. void method()
  22. {
  23. cout << M << endl;
  24. }
  25. };
  26.  
  27. int main(int argc, const char * argv[])
  28. {
  29. Test<int,0> t1;
  30. t1.method();
  31. Test<int,5> t2;
  32. t2.method();
  33. Test<char,7> t3;
  34. t3.method();
  35. Test<char,7,15> t4;
  36. t4.method();
  37. }
  38.  
  39.  
  40.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
5
3
7
15