| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | // LWG 4112. has-arrow should required operator->() to be const-qualified |
| 4 | |
| 5 | // The issue resolution means that range adaptors which use has-arrow to |
| 6 | // constrain their iterator's operator-> should require a const-qualified |
| 7 | // operator-> on the underlying view's iterator. |
| 8 | |
| 9 | #include <ranges> |
| 10 | |
| 11 | struct Int { int i = 0; }; |
| 12 | |
| 13 | struct Iter |
| 14 | { |
| 15 | using value_type = Int; |
| 16 | using difference_type = int; |
| 17 | |
| 18 | mutable Int val; |
| 19 | |
| 20 | Int& operator*() const { return val; } |
| 21 | Int* operator->() /* non-const */ { return &val; } |
| 22 | Iter& operator++() { ++val.i; return *this; } |
| 23 | void operator++(int) { ++val.i; } |
| 24 | bool operator==(const Iter& j) const { return val.i == j.val.i; } |
| 25 | }; |
| 26 | |
| 27 | template<typename T> |
| 28 | concept has_op_arrow = requires (T t) { t.operator->(); }; |
| 29 | |
| 30 | static_assert( has_op_arrow<Iter> ); |
| 31 | static_assert( ! has_op_arrow<const Iter> ); |
| 32 | |
| 33 | using Range = std::ranges::subrange<Iter>; |
| 34 | using Pred = bool(*)(Int); |
| 35 | using FilterView = std::ranges::filter_view<Range, Pred>; |
| 36 | using FilterIterator = std::ranges::iterator_t<FilterView>; |
| 37 | |
| 38 | static_assert( ! has_op_arrow<FilterIterator> ); |
| 39 | static_assert( ! has_op_arrow<FilterIterator&> ); |
| 40 | static_assert( ! has_op_arrow<FilterIterator const> ); |
| 41 | static_assert( ! has_op_arrow<FilterIterator const&> ); |