To find the max element of any vector, we can use std::max_element(...) and then deference the returned iterator, or iterate over all the elements and use the std::max(const T& a, const T& b, Compare comp) function to get the maximum value.
If I see the interfaces defined for std::max, then we have
std::max (initializer_list<T> il, Compare comp)
but there isn't anything for vector, array and list etc. We can try and convert the intended container into an initializer_list and then use this interface, but is there any specific reason why we don't have something similar to this interface for other container classes?
Aucun commentaire:
Enregistrer un commentaire