212. Empty range behavior unclear for several algorithms

Section: 28.7.8 [alg.min.max] Status: TC1 Submitter: Nico Josuttis Opened: 2000-02-26 Last modified: 2016-02-10

Priority: Not Prioritized

View all other issues in [alg.min.max].

View all issues with TC1 status.

Discussion:

The standard doesn't specify what min_element() and max_element() shall return if the range is empty (first equals last). The usual implementations return last. This problem seems also apply to partition(), stable_partition(), next_permutation(), and prev_permutation().

Proposed resolution:

In 28.7.8 [alg.min.max] - Minimum and maximum, paragraphs 7 and 9, append: Returns last if first==last.

Rationale:

The LWG looked in some detail at all of the above mentioned algorithms, but believes that except for min_element() and max_element() it is already clear that last is returned if first == last.