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, c++20 |
10 | |
11 | // constexpr iterator(iterator<!Const> i) |
12 | // requires Const && (convertible_to<iterator_t<Views>, |
13 | // iterator_t<maybe-const<Const, Views>>> && ...); |
14 | |
15 | #include <ranges> |
16 | |
17 | #include <cassert> |
18 | #include <tuple> |
19 | |
20 | #include "../types.h" |
21 | |
22 | using ConstIterIncompatibleView = BasicView<forward_iterator<int*>, forward_iterator<int*>, |
23 | random_access_iterator<const int*>, random_access_iterator<const int*>>; |
24 | static_assert(!std::convertible_to<std::ranges::iterator_t<ConstIterIncompatibleView>, |
25 | std::ranges::iterator_t<const ConstIterIncompatibleView>>); |
26 | |
27 | constexpr bool test() { |
28 | int buffer[3] = {1, 2, 3}; |
29 | |
30 | { |
31 | std::ranges::zip_view v(NonSimpleCommon{buffer}); |
32 | auto iter1 = v.begin(); |
33 | std::ranges::iterator_t<const decltype(v)> iter2 = iter1; |
34 | assert(iter1 == iter2); |
35 | |
36 | static_assert(!std::is_same_v<decltype(iter1), decltype(iter2)>); |
37 | |
38 | // We cannot create a non-const iterator from a const iterator. |
39 | static_assert(!std::constructible_from<decltype(iter1), decltype(iter2)>); |
40 | } |
41 | |
42 | { |
43 | // underlying non-const to const not convertible |
44 | std::ranges::zip_view v(ConstIterIncompatibleView{buffer}); |
45 | auto iter1 = v.begin(); |
46 | auto iter2 = std::as_const(v).begin(); |
47 | |
48 | static_assert(!std::is_same_v<decltype(iter1), decltype(iter2)>); |
49 | |
50 | static_assert(!std::constructible_from<decltype(iter1), decltype(iter2)>); |
51 | static_assert(!std::constructible_from<decltype(iter2), decltype(iter1)>); |
52 | } |
53 | |
54 | return true; |
55 | } |
56 | |
57 | int main(int, char**) { |
58 | test(); |
59 | static_assert(test()); |
60 | |
61 | return 0; |
62 | } |
63 | |