212. Empty range behavior unclear for several algorithms

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

Priority: Not Prioritized

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

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 26.8.9 [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.