c++ clamp

C++
int n = -1;
const int& r = std::clamp(n, 0, 255);
// r is dangling
Source

Also in C++: