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