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 I2, class S2>
12 // requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
13 // constexpr common_iterator(const common_iterator<I2, S2>& x);
14
15 #include <iterator>
16 #include <cassert>
17
18 #include "test_macros.h"
19
test()20 constexpr bool test()
21 {
22 struct Base {};
23 struct Derived : Base {};
24
25 using BaseIt = std::common_iterator<Base*, const Base*>;
26 using DerivedIt = std::common_iterator<Derived*, const Derived*>;
27 static_assert(std::is_convertible_v<DerivedIt, BaseIt>); // Derived* to Base*
28 static_assert(!std::is_constructible_v<DerivedIt, BaseIt>); // Base* to Derived*
29
30 Derived a[10] = {};
31 DerivedIt it = DerivedIt(a); // the iterator type
32 BaseIt jt = BaseIt(it);
33 assert(jt == BaseIt(a));
34
35 it = DerivedIt((const Derived*)a); // the sentinel type
36 jt = BaseIt(it);
37 assert(jt == BaseIt(a));
38
39 return true;
40 }
41
main(int,char **)42 int main(int, char**) {
43 test();
44 static_assert(test());
45
46 return 0;
47 }
48