Skip to content

Instantly share code, notes, and snippets.

@dhasenan dhasenan/clamp.d
Created Apr 12, 2018

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
You can’t perform that action at this time.