convert.pass.cpp (1442B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <iterator> 11 12 // move_iterator 13 14 // template <class U> 15 // requires HasConstructor<Iter, const U&> 16 // move_iterator(const move_iterator<U> &u); 17 // 18 // constexpr in C++17 19 20 #include <iterator> 21 #include <cassert> 22 23 #include "test_macros.h" 24 #include "test_iterators.h" 25 26 template <class It, class U> 27 void 28 test(U u) 29 { 30 const std::move_iterator<U> r2(u); 31 std::move_iterator<It> r1 = r2; 32 assert(r1.base() == u); 33 } 34 35 struct Base {}; 36 struct Derived : Base {}; 37 38 int main() 39 { 40 Derived d; 41 42 test<input_iterator<Base*> >(input_iterator<Derived*>(&d)); 43 test<forward_iterator<Base*> >(forward_iterator<Derived*>(&d)); 44 test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d)); 45 test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d)); 46 test<Base*>(&d); 47 48 #if TEST_STD_VER > 14 49 { 50 constexpr const Derived *p = nullptr; 51 constexpr std::move_iterator<const Derived *> it1 = std::make_move_iterator(p); 52 constexpr std::move_iterator<const Base *> it2(it1); 53 static_assert(it2.base() == p); 54 } 55 #endif 56 }