This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.

### 2967. `std::equal` on empty ranges

Section: 25.6.11 [alg.equal] Status: NAD Submitter: Gennaro Prota Opened: 2017-05-26 Last modified: 2020-09-06

Priority: Not Prioritized

View all other issues in [alg.equal].

View all issues with NAD status.

Discussion:

The description of the `std::equal()` algorithm in the standard doesn't make clear what the result of it is on empty ranges:

>     std::equal(first, first, second) ; // what does this return?

It should IMHO return true (two empty ranges are always equal).

[2017-07 Toronto Monday issue prioritization]

Closing as NAD; the existing wording covers empty sequences

Proposed resolution:

This wording is relative to N4659.

1. Edit 25.6.11 [alg.equal] as indicated:

   > [Drafting note: The current wording presented below uses two times the unusual phrase "[…] return […]" instead of "[…] returns […]". The project editor is kindly asked to consider to replace these unusual wording forms by the usual one. — end drafting note]

   >     template<class InputIterator1, class InputIterator2>
   >       bool equal(InputIterator1 first1, InputIterator1 last1,
   >                  InputIterator2 first2);
   >     […]

   > > -1- Remarks: If `last2` was not given in the argument list, it denotes `first2 + (last1 - first1)` below.

   > > -2- Returns: If `[first1, last1)` and `[first2, last2)` are both empty, returns `true`. If `last1 - first1 != last2 - first2`, return `false`. Otherwise return `true` if for every iterator `i` in the range `[first1, last1)` the following corresponding conditions hold: `*i == *(first2 + (i - first1)), pred(*i, *(first2 + (i - first1))) != false`. Otherwise, returns `false`.

   > > […]