최대 1 분 소요

개요

  • 최소값 보다 작으면 최소값, 최대 값 보다 크면 최대 값을 반환하는 함수


예제

  • 코드
    #include <algorithm>
    #include <iostream>

    using namespace std;

    int main() {
    	auto func = [](auto i) { return clamp(i, 1, 10); };

    	cout << func(0) << endl;

    	cout << func(1) << endl;

    	cout << func(2) << endl;

    	cout << func(9) << endl;

    	cout << func(10) << endl;

    	cout << func(11) << endl;

    	return 0;
    }
  • 실행 결과
    1
    1
    2
    9
    10
    10