Title
Requirements on function objects passed to {forward_,}list-specific algorithms
Status
c++20
Section
[list.ops][forward.list.ops]
Submitter
Tim Song

Created on 2017-07-07.00:00:00 last changed 38 months ago

Messages

Date: 2017-07-12.01:58:24

Proposed resolution:

This wording is relative to N4659.

  1. Edit [list.ops] as indicated:

    -1- Since lists allow fast insertion and erasing from the middle of a list, certain operations are provided specifically for them.259) In this subclause, arguments for a template parameter named Predicate or BinaryPredicate shall meet the corresponding requirements in [algorithms.requirements]. For merge and sort, the definitions and requirements in [alg.sorting] apply.

  2. Edit [list.ops] as indicated:

    void merge(list& x);
    void merge(list&& x);
    template <class Compare> void merge(list& x, Compare comp);
    template <class Compare> void merge(list&& x, Compare comp);
    

    -22- Requires: comp shall define a strict weak ordering ([alg.sorting]), and bBoth the list and the argument list shall be sorted according to this orderingwith respect to the comparator operator< (for the first two overloads) or comp (for the last two overloads).

  3. Delete [list.ops]/28 as redundant:

    void sort();
    template <class Compare> void sort(Compare comp);
    

    -28- Requires: operator< (for the first version) or comp (for the second version) shall define a strict weak ordering ([alg.sorting]).

  4. Insert a new paragraph at the beginning of [forwardlist.ops]:

    -?- In this subclause, arguments for a template parameter named Predicate or BinaryPredicate shall meet the corresponding requirements in [algorithms.requirements]. For merge and sort, the definitions and requirements in [alg.sorting] apply.

    void splice_after(const_iterator position, forward_list& x);
    void splice_after(const_iterator position, forward_list&& x);
    

    […]

  5. Edit [forwardlist.ops] as indicated:

    void merge(forward_list& x);
    void merge(forward_list&& x);
    template <class Compare> void merge(forward_list& x, Compare comp);
    template <class Compare> void merge(forward_list&& x, Compare comp);
    

    -22- Requires: comp defines a strict weak ordering ([alg.sorting]), and *this and x are both sorted according to this orderingwith respect to the comparator operator< (for the first two overloads) or comp (for the last two overloads). get_allocator() == x.get_allocator().

  6. Delete [forwardlist.ops]/23 as redundant:

    void sort();
    template <class Compare> void sort(Compare comp);
    

    -23- Requires: operator< (for the version with no arguments) or comp (for the version with a comparison argument) defines a strict weak ordering ([alg.sorting]).

Date: 2017-07-12.01:58:24

[ 2017-07 Toronto Tuesday PM issue prioritization ]

Priority 0; status to Ready

Date: 2017-07-07.00:00:00

Some specialized algorithms for forward_list and list take template parameters named Predicate, BinaryPredicate, or Compare. However, there's no wording importing the full requirements for template type parameters with such names from [algorithms.requirements] and [alg.sorting], which means, for instance, that there appears to be no rule prohibiting Compare from modifying its arguments, because we only refer to [alg.sorting] for the definition of strict weak ordering. Is that intended?

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:34:55adminsetstatus: ready -> voting
2017-07-12 01:58:24adminsetmessages: + msg9361
2017-07-12 01:58:24adminsetstatus: new -> ready
2017-07-08 14:21:32adminsetmessages: + msg9328
2017-07-07 00:00:00admincreate