Yes, it will work correctly. The overload of std::max_element to be called in this case is
template< class ForwardIt > ForwardIt max_element(ForwardIt first, ForwardIt last);
The only requirements for iterators are
first , last - forward iterators defining the range to study
Thus, there are no requirements for random access iterators, but only for iterators.
source share