Library Feature: std::clamp

Definition

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

Syntax

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.

You may also like...

Leave a Reply