mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
clamp: added variant clamp_nonzero() to only clamp non-zero values
This is useful for clamping parameter values to a range, but where zero is a special case (for example to disable the parameter). Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
parent
905ee72fe3
commit
7e484e1fa7
@ -36,4 +36,13 @@ namespace openvpn {
|
||||
return value;
|
||||
}
|
||||
|
||||
// like clamp() above, but only clamp non-zero values
|
||||
template <typename T>
|
||||
T clamp_nonzero(T value, T low, T high)
|
||||
{
|
||||
if (value)
|
||||
return clamp(value, low, high);
|
||||
else
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user