Код / C++
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> Numbers{ 0, 1, 2, 3, 4, 5, 6, 7, 8 };
for (std::vector<int>::iterator it = Numbers.begin(); it != Numbers.end(); ++it)
{
std::cout << *it << ' ';
}
// 0 1 2 3 4 5 6 7 8
}
#include <iostream>
class Clamp
{
public:
int operator() (int Value, int Min, int Max) const
{
return Value < Min ? Min : Value < Max ? Value : Max;
}
};
int main()
{
Clamp clamp;
std::cout<< clamp(40, 0, 30) << std::endl; // 30
std::cout<< clamp(-1, 0, 30) << std::endl; // 0
std::cout<< clamp(15, 0, 30) << std::endl; // 15
}
Last updated