0
0
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:
James Yonan 2021-08-12 07:56:41 -06:00
parent 905ee72fe3
commit 7e484e1fa7

View File

@ -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;
}
}