Why does std::min only support initializer_list?
问题 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::vector or std::list , Because the param in the template is initializer_list . template <class T, class Compare> pair<T,T> minmax (initializer_list<T> il, Compare comp); What is the reason for this design? 回答1: To explain "why it doesn't accept a container", take the semantic into consideration: std::min({ "foo", "bar", "hello" }) The semantic of std::min() means "find