fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <int nMin = 0, int nMax = 5>
  5. int clamp_asdf(int n)
  6. {
  7. return n < nMin ? nMin : n <= nMax ? n : nMax;
  8. }
  9.  
  10. template <>
  11. int clamp_asdf<0, 0>(int n)
  12. {
  13. cout << "clamp_asdf<0, 0>\n";
  14. return 0;
  15. }
  16.  
  17.  
  18. int main() {
  19. cout << clamp_asdf(8) << endl;
  20. cout << clamp_asdf<7,10>(8) << endl;
  21. cout << clamp_asdf<0,0>(8) << endl;
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
5
8
clamp_asdf<0, 0>
0