We can use std::min
in below way:
// 1.
int a = 1, b = 2;
std::min(a, b);
// 2.
std::min({1,2,3,4});
But why can\'t use a std
But why can't use a std::vector or std::list, Because the param in the template is initializer_list.
Because there is no overload that would accept a vector or a list. Those are not initialiser lists.
Since C++20 you can use std::ranges::min
into which you can pass either of those containers or indeed any range. Prior to that, there is std::min_element
which works with any pair of iterators.