0

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?

Dinesh Maurya
  • 822
  • 8
  • 24
  • Algorithms support *all* containers, even those not provided by the standard library. Why does there need to be a special function for *just* those containers only? – Nicol Bolas Nov 22 '20 at 02:42
  • Answer from @JaMiT on the linked question makes things clear to me for the reasoning behid having this special overload for initializer_list and not for other containers. – Dinesh Maurya Nov 22 '20 at 06:20

0 Answers0