xref: /llvm-project/libcxx/test/std/ranges/range.req/range.refinements/common_range.compile.pass.cpp (revision d8fad6614923eea684f736e7d22fe54d5393f13f)
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 // UNSUPPORTED: libcpp-no-concepts
11 
12 // template<class T>
13 // concept common_range;
14 
15 #include <ranges>
16 
17 #include "test_iterators.h"
18 #include "test_range.h"
19 
20 namespace stdr = std::ranges;
21 
22 static_assert(!stdr::common_range<test_range<cpp17_input_iterator> >);
23 static_assert(!stdr::common_range<test_range<cpp17_input_iterator> const>);
24 
25 static_assert(!stdr::common_range<test_non_const_range<cpp17_input_iterator> >);
26 static_assert(!stdr::common_range<test_non_const_range<cpp17_input_iterator> const>);
27 
28 static_assert(stdr::common_range<test_common_range<cpp17_input_iterator> >);
29 static_assert(stdr::common_range<test_common_range<cpp17_input_iterator> const>);
30 
31 static_assert(stdr::common_range<test_non_const_common_range<cpp17_input_iterator> >);
32 static_assert(!stdr::common_range<test_non_const_common_range<cpp17_input_iterator> const>);
33 
34 struct subtly_not_common {
35   int* begin() const;
36   int const* end() const;
37 };
38 static_assert(stdr::range<subtly_not_common> && !stdr::common_range<subtly_not_common>);
39 static_assert(stdr::range<subtly_not_common const> && !stdr::common_range<subtly_not_common const>);
40 
41 struct common_range_non_const_only {
42   int* begin() const;
43   int* end();
44   int const* end() const;
45 };
46 static_assert(stdr::range<common_range_non_const_only>&& stdr::common_range<common_range_non_const_only>);
47 static_assert(stdr::range<common_range_non_const_only const> && !stdr::common_range<common_range_non_const_only const>);
48 
49 struct common_range_const_only {
50   int* begin();
51   int const* begin() const;
52   int const* end() const;
53 };
54 static_assert(stdr::range<common_range_const_only> && !stdr::common_range<common_range_const_only>);
55 static_assert(stdr::range<common_range_const_only const>&& stdr::common_range<common_range_const_only const>);
56