Eri*_*ric 2 c++ max min clamp
我试图确保int x大于或等于0但小于1080(在这种情况下是屏幕尺寸).
int x
我想出了这个
int x = 123; x = std::min(std::max(x, 0), 1080);
这看起来很难看.有没有更好的方法来实现这一目标?
mel*_*ene 8
如果您将来生活,可以使用std::clampC++ 17:
std::clamp
x = std::clamp(x, 0, 1080);
归档时间:
9 年,2 月 前
查看次数:
229 次
最近记录: