| 1 | // Test the example from P2997R1 "Removing the common reference requirement |
| 2 | // from the indirectly invocable concepts". |
| 3 | // { dg-do compile { target c++20 } } |
| 4 | |
| 5 | #include <algorithm> |
| 6 | #include <ranges> |
| 7 | |
| 8 | struct C { |
| 9 | auto f() -> void; |
| 10 | }; |
| 11 | |
| 12 | struct Iterator { |
| 13 | using value_type = C; |
| 14 | using difference_type = std::ptrdiff_t; |
| 15 | using iterator_category = std::input_iterator_tag; |
| 16 | |
| 17 | auto operator*() const -> C&&; |
| 18 | auto operator++() -> Iterator&; |
| 19 | auto operator++(int) -> void; |
| 20 | auto operator==(Iterator const&) const -> bool; |
| 21 | }; |
| 22 | |
| 23 | static_assert(std::input_iterator<Iterator>); |
| 24 | static_assert(std::same_as<std::iter_value_t<Iterator>, C>); |
| 25 | static_assert(std::same_as<std::iter_reference_t<Iterator>, C&&>); |
| 26 | |
| 27 | struct R { |
| 28 | auto begin() -> Iterator; |
| 29 | auto end() -> Iterator; |
| 30 | }; |
| 31 | |
| 32 | static_assert(std::ranges::range<R>); |
| 33 | static_assert(std::same_as<std::ranges::range_reference_t<R>, C&&>); |
| 34 | |
| 35 | auto f(R r) -> void { |
| 36 | std::ranges::for_each(r, [](auto&& c){ c.f(); }); |
| 37 | } |