Title
ValueSwappable requirement missing for push_heap and make_heap
Status
c++23
Section
[alg.heap.operations]
Submitter
Robert Douglas

Created on 2017-11-08.00:00:00 last changed 4 months ago

Messages

Date: 2023-02-13.10:17:57

Proposed resolution:

This wording is relative to N4917.

  1. Change [push.heap] as indicated:

    template<class RandomAccessIterator>
      constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last);
    
    template<class RandomAccessIterator, class Compare>
      constexpr void push_heap(RandomAccessIterator first, RandomAccessIterator last,
                               Compare comp);
                     
    template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
             class Proj = identity>
      requires sortable<I, Comp, Proj>
      constexpr I
        ranges::push_heap(I first, S last, Comp comp = {}, Proj proj = {});
    template<random_access_range R, class Comp = ranges::less, class Proj = identity>
      requires sortable<iterator_t<R>, Comp, Proj>
      constexpr borrowed_iterator_t<R>
        ranges::push_heap(R&& r, Comp comp = {}, Proj proj = {});
    

    -1- Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.

    -2- Preconditions: The range [first, last - 1) is a valid heap with respect to comp and proj. For the overloads in namespace std, RandomAccessIterator meets the Cpp17ValueSwappable requirements ([swappable.requirements]) and the type of *first meets the Cpp17MoveConstructible requirements (Table 32) and the Cpp17MoveAssignable requirements (Table 34).

    -3- Effects: Places the value in the location last - 1 into the resulting heap [first, last).

    -4- Returns: last for the overloads in namespace ranges.

    -5- Complexity: At most log(last - first) comparisons and twice as many projections.

  2. Change [make.heap] as indicated:

    template<class RandomAccessIterator>
      constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last);
    
    template<class RandomAccessIterator, class Compare>
      constexpr void make_heap(RandomAccessIterator first, RandomAccessIterator last,
                               Compare comp);
                               
    template<random_access_iterator I, sentinel_for<I> S, class Comp = ranges::less,
             class Proj = identity>
      requires sortable<I, Comp, Proj>
      constexpr I
        ranges::make_heap(I first, S last, Comp comp = {}, Proj proj = {});
    template<random_access_range R, class Comp = ranges::less, class Proj = identity>
      requires sortable<iterator_t<R>, Comp, Proj>
      constexpr borrowed_iterator_t<R>
        ranges::make_heap(R&& r, Comp comp = {}, Proj proj = {});
    

    -1- Let comp be less{} and proj be identity{} for the overloads with no parameters by those names.

    -2- Preconditions: For the overloads in namespace std, RandomAccessIterator meets the Cpp17ValueSwappable requirements ([swappable.requirements]) and the type of *first meets the Cpp17MoveConstructible (Table 32) and Cpp17MoveAssignable (Table 34) requirements.

    -3- Effects: Constructs a heap with respect to comp and proj out of the range [first, last).

    -4- Returns: last for the overloads in namespace ranges.

    -5- Complexity: At most 3(last - first) comparisons and twice as many projections.

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]

Date: 2022-11-10.01:48:17

[ Kona 2022-11-09; Move to Ready ]

Date: 2022-11-15.00:00:00

[ 2022-11-06; Daniel comments and syncs wording with recent working draft ]

For reference, the finally accepted paper was P0202R3 and the constexpr-ification of swap-related algorithms had been realized later by P0879R0 after resolution of CWG 1581 and more importantly CWG 1330.

Date: 2022-11-06.12:07:45

[ 2017-11 Albuquerque Wednesday night issues processing ]

Priority set to 3; Marshall to investigate

Previous resolution [SUPERSEDED]:

This wording is relative to N4700.

  1. Change [push.heap] as indicated:

    template<class RandomAccessIterator>
      void push_heap(RandomAccessIterator first, RandomAccessIterator last);
    template<class RandomAccessIterator, class Compare>
      void push_heap(RandomAccessIterator first, RandomAccessIterator last,
                     Compare comp);
    

    -1- Requires: The range [first, last - 1) shall be a valid heap. RandomAccessIterator shall satisfy the requirements of ValueSwappable ([swappable.requirements]). The type of *first shall satisfy the MoveConstructible requirements (Table 23) and the MoveAssignable requirements (Table 25).

  2. Change [make.heap] as indicated:

    template<class RandomAccessIterator>
      void make_heap(RandomAccessIterator first, RandomAccessIterator last);
    template<class RandomAccessIterator, class Compare>
      void make_heap(RandomAccessIterator first, RandomAccessIterator last,
                     Compare comp);
    

    -1- Requires: RandomAccessIterator shall satisfy the requirements of ValueSwappable ([swappable.requirements]). The type of *first shall satisfy the MoveConstructible requirements (Table 23) and the MoveAssignable requirements (Table 25).

Date: 2017-11-08.21:17:55

In discussion of D0202R3 in Albuquerque, it was observed that pop_heap and sort_heap had constexpr removed for their requirement of ValueSwappable. It was then observed that push_heap and make_heap were not similarly marked as having the ValueSwappable requirement. The room believed this was likely a specification error, and asked to open an issue to track it.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 10:17:57adminsetmessages: + msg13348
2023-02-13 10:17:57adminsetstatus: voting -> wp
2023-02-06 15:33:48adminsetstatus: ready -> voting
2022-11-10 01:48:17adminsetmessages: + msg12985
2022-11-10 01:48:17adminsetstatus: new -> ready
2022-11-06 12:07:45adminsetmessages: + msg12936
2017-11-09 15:13:04adminsetmessages: + msg9529
2017-11-08 21:10:22adminsetmessages: + msg9512
2017-11-08 00:00:00admincreate