Title
The const overloads of take_while_view::begin/end are underconstrained
Status
c++23
Section
[range.take.while.view]
Submitter
Tim Song

Created on 2020-06-06.00:00:00 last changed 13 months ago

Messages

Date: 2020-11-09.20:31:48

Proposed resolution:

This wording is relative to N4861.

  1. Modify [range.take.while.view], class template take_while_view synopsis, as indicated:

    namespace std::ranges {
        template<view V, class Pred>
          requires input_range<V> && is_object_v<Pred> &&
                   indirect_unary_predicate<const Pred, iterator_t<V>>
        class take_while_view : public view_interface<take_while_view<V, Pred>> {
        […]
    
        constexpr auto begin() requires (!simple-view<V>)
        { return ranges::begin(base_); }
    
        constexpr auto begin() const requires range<const V> && indirect_unary_predicate<const Pred, iterator_t<const V>>
        { return ranges::begin(base_); }
    
        constexpr auto end() requires (!simple-view<V>)
        { return sentinel<false>(ranges::end(base_), addressof(*pred_)); }
    
        constexpr auto end() const requires range<const V> && indirect_unary_predicate<const Pred, iterator_t<const V>>
        { return sentinel<true>(ranges::end(base_), addressof(*pred_)); }
        };
    }
    
Date: 2020-11-09.00:00:00

[ 2020-11-09 Approved In November virtual meeting. Status changed: Ready → WP. ]

Date: 2020-07-15.00:00:00

[ 2020-07-17; Moved to Ready in telecon ]

Date: 2020-06-06.00:00:00

The const overloads of take_while_view::begin and take_while_view::end are underconstrained: they should require the predicate to model indirect_unary_predicate<iterator_t<const V>>. A simple example is

    #include <ranges>

    auto v = std::views::single(1) | std::views::take_while([](int& x) { return true;});
    static_assert(std::ranges::range<decltype(v)>);
    static_assert(std::ranges::range<decltype(v) const>);
    bool b = std::ranges::cbegin(v) == std::ranges::cend(v);

Here, the static_asserts pass but the comparison fails to compile. The other views using indirect_unary_predicate (filter_view and drop_while_view) do not have this problem because they do not support const-iteration.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 20:31:48adminsetmessages: + msg11549
2020-11-09 20:31:48adminsetstatus: ready -> wp
2020-07-17 22:37:26adminsetmessages: + msg11395
2020-07-17 22:37:26adminsetstatus: new -> ready
2020-06-06 13:46:40adminsetmessages: + msg11325
2020-06-06 00:00:00admincreate