| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | // template<class R, class T> |
| 12 | // concept output_range; |
| 13 | |
| 14 | #include <ranges> |
| 15 | |
| 16 | #include <iterator> |
| 17 | #include "test_iterators.h" |
| 18 | #include "test_range.h" |
| 19 | |
| 20 | struct T { }; |
| 21 | |
| 22 | // Satisfied when it's a range and has the right iterator |
| 23 | struct GoodRange { |
| 24 | cpp17_output_iterator<T*> begin(); |
| 25 | sentinel end(); |
| 26 | }; |
| 27 | static_assert(std::ranges::range<GoodRange>); |
| 28 | static_assert(std::output_iterator<std::ranges::iterator_t<GoodRange>, T>); |
| 29 | static_assert(std::ranges::output_range<GoodRange, T>); |
| 30 | |
| 31 | // Not satisfied when it's not a range |
| 32 | struct NotRange { |
| 33 | cpp17_output_iterator<T*> begin(); |
| 34 | }; |
| 35 | static_assert(!std::ranges::range<NotRange>); |
| 36 | static_assert( std::output_iterator<std::ranges::iterator_t<NotRange>, T>); |
| 37 | static_assert(!std::ranges::output_range<NotRange, T>); |
| 38 | |
| 39 | // Not satisfied when the iterator is not an output_iterator |
| 40 | struct RangeWithBadIterator { |
| 41 | cpp17_input_iterator<T const*> begin(); |
| 42 | sentinel end(); |
| 43 | }; |
| 44 | static_assert( std::ranges::range<RangeWithBadIterator>); |
| 45 | static_assert(!std::output_iterator<std::ranges::iterator_t<RangeWithBadIterator>, T>); |
| 46 | static_assert(!std::ranges::output_range<RangeWithBadIterator, T>); |
| 47 | |
| 48 | // Test ADL-proofing. |
| 49 | struct Incomplete; |
| 50 | template<class T> struct Holder { T t; }; |
| 51 | |
| 52 | static_assert(!std::ranges::output_range<Holder<Incomplete>*, Holder<Incomplete>*>); |
| 53 | static_assert(!std::ranges::output_range<Holder<Incomplete>*&, Holder<Incomplete>*>); |
| 54 | static_assert(!std::ranges::output_range<Holder<Incomplete>*&&, Holder<Incomplete>*>); |
| 55 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const, Holder<Incomplete>*>); |
| 56 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const&, Holder<Incomplete>*>); |
| 57 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const&&, Holder<Incomplete>*>); |
| 58 | |
| 59 | static_assert( std::ranges::output_range<Holder<Incomplete>*[10], Holder<Incomplete>*>); |
| 60 | static_assert( std::ranges::output_range<Holder<Incomplete>*(&)[10], Holder<Incomplete>*>); |
| 61 | static_assert( std::ranges::output_range<Holder<Incomplete>*(&&)[10], Holder<Incomplete>*>); |
| 62 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const[10], Holder<Incomplete>*>); |
| 63 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const(&)[10], Holder<Incomplete>*>); |
| 64 | static_assert(!std::ranges::output_range<Holder<Incomplete>* const(&&)[10], Holder<Incomplete>*>); |
| 65 | |