The cool bit about it compared to juce::jlimit is that it can be used in constexpr circumstances. Worth noting that std::clamp is only available in C++17.
// Somewhere in juce_CompilerSupport.h:
#if ! JUCE_CXX17_IS_AVAILABLE
namespace std
{
template<class T>
constexpr const T& clamp (const T& v, const T& lo, const T& hi)
{
return (v < lo) ? lo : (hi < v) ? hi : v;
}
template<class T, class Compare>
constexpr const T& clamp (const T& v, const T& lo, const T& hi, Compare comp)
{
return comp (v, lo) ? lo : comp (hi, v) ? hi : v;
}
}
#endif
