프로그래밍/c++

std::clamp

제페 2019. 11. 24. 16:03
반응형

정의 헤더

<algorithm> (since c++17)

기능

값을 범위 안으로 보정

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    int v0 = -1;
    
    cout << "clamp v0: " << clamp(v0, 0, 10) << endl; // 0
    
    int v1 = 11;
    cout << "clamp v1: " << clamp(v1, 0, 10) << endl; // 10
    
    return 0;
}

 

https://en.cppreference.com/w/cpp/algorithm/clamp

반응형