57. Threshold Default Template Arguments

Write a function template thresholdOrDefault logic. 
It returns either the given value or a safe default:

template<typename T = int> 

T thresholdOrDefault(T v, T def = {})

  • If v < 0, return def.
  • Otherwise, return v.
     

The program already reads a value and optionally a default, and calls thresholdOrDefault.
 You only need to implement the template function.

 

Example
 Input:

5

Output:

5

 

Input:

-3

Output:

0

 

Input:

-3 100

Output:

100
Loading...

Input

5

Expected Output

5