The clamp functions are badly designed

Xavier Jouvenot
4 min readOct 5, 2022

Hello ! I’m Xavier Jouvenot and today, we are going to see why the std::clamp and std::ranges::clamp functions of the C++ standard are badly designed and how we can simply improve it.

Self promotion: Here are a few social networks where you can follow me and check my work as a programmer and a writer 😉 Personal blog, Twitter, GitHub

The issue with std::clamp and std::ranges::clamp

Since C++17, the function std::clamp is available as a helper to keep a variable in a range of value…