Library Feature: std::clamp



Clamp is an algorithm added in C++17 that is used to limit a value in a given range. 

  • If value > max, value is set to max
  • If value < min, value is set to min


Before C++17, we were relying on the following code (or similar) to clamp a value.

Now, with C++17, we can simply use std::clamp.

Leave a comment

Your email address will not be published.