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// constexpr iterator(iterator<!Const> i)
12// requires Const &&
13// convertible_to<iterator_t<V>, OuterIter> &&
14// convertible_to<iterator_t<InnerRng>, InnerIter>;
15
16#include <cassert>
17#include <ranges>
18
19#include "test_macros.h"
20#include "../types.h"
21
22using ConstCompatibleInner = BufferView<int*>;
23
24using ConstIncompatibleInner = BufferView<forward_iterator<const int*>, forward_iterator<const int*>,
25 bidirectional_iterator<int*>, bidirectional_iterator<int*>>;
26
27template <class Inner>
28using ConstCompatibleOuter = BufferView<const Inner*, const Inner*, Inner*, Inner*>;
29
30template <class Inner>
31using ConstIncompatibleOuter = BufferView<forward_iterator<const Inner*>, forward_iterator<const Inner*>,
32 bidirectional_iterator<Inner*>, bidirectional_iterator<Inner*>>;
33
34constexpr bool test() {
35 int buffer[4][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
36 {
37 CopyableChild children[4] = {CopyableChild(buffer[0]), CopyableChild(buffer[1]), CopyableChild(buffer[2]),
38 CopyableChild(buffer[3])};
39 std::ranges::join_view jv(ForwardCopyableParent{children});
40 auto iter1 = jv.begin();
41 using iterator = decltype(iter1);
42 using const_iterator = decltype(std::as_const(jv).begin());
43 static_assert(!std::is_same_v<iterator, const_iterator>);
44 const_iterator iter2 = iter1;
45 assert(iter1 == iter2);
46
47 // We cannot create a non-const iterator from a const iterator.
48 static_assert(!std::constructible_from<iterator, const_iterator>);
49 }
50
51 // !convertible_to<inner_iterator, inner_const_iterator>>;
52 {
53 ConstIncompatibleInner inners[2] = {buffer[0], buffer[1]};
54 ConstCompatibleOuter<ConstIncompatibleInner> outer{inners};
55 std::ranges::join_view jv(outer);
56 using iterator = decltype(jv.begin());
57 using const_iterator = decltype(std::as_const(jv).begin());
58 static_assert(!std::is_same_v<iterator, const_iterator>);
59
60 static_assert(!std::constructible_from<const_iterator, iterator>);
61 static_assert(!std::constructible_from<iterator, const_iterator>);
62 }
63
64 // !convertible_to<outer_iterator, outer_const_iterator>>;
65 {
66 ConstCompatibleInner inners[2] = {buffer[0], buffer[1]};
67 ConstIncompatibleOuter<ConstCompatibleInner> outer{inners};
68 std::ranges::join_view jv(outer);
69 using iterator = decltype(jv.begin());
70 using const_iterator = decltype(std::as_const(jv).begin());
71 static_assert(!std::is_same_v<iterator, const_iterator>);
72
73 static_assert(!std::constructible_from<const_iterator, iterator>);
74 static_assert(!std::constructible_from<iterator, const_iterator>);
75 }
76
77 return true;
78}
79
80int main(int, char**) {
81 test();
82 static_assert(test());
83
84 return 0;
85}
86

source code of libcxx/test/std/ranges/range.adaptors/range.join/range.join.iterator/ctor.other.pass.cpp