Instantly share code, notes, and snippets.

Embed
What would you like to do?
clamp value with contracts
T clamp(T)(T min, T max, T value)
in
{
assert(min <= max);
}
do
{
if (min > value) return min;
if (max < value) return max;
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment