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 HasAssign<Iter, const U&> 16 // move_iterator& 17 // operator=(const move_iterator<U>& u); 18 // 19 // constexpr in C++17 20 21 #include <iterator> 22 #include <cassert> 23 24 #include "test_macros.h" 25 #include "test_iterators.h" 26 27 template <class It, class U> 28 void 29 test(U u) 30 { 31 const std::move_iterator<U> r2(u); 32 std::move_iterator<It> r1; 33 std::move_iterator<It>& rr = r1 = r2; 34 assert(r1.base() == u); 35 assert(&rr == &r1); 36 } 37 38 struct Base {}; 39 struct Derived : Base {}; 40 41 int main() 42 { 43 Derived d; 44 45 test<input_iterator<Base*> >(input_iterator<Derived*>(&d)); 46 test<forward_iterator<Base*> >(forward_iterator<Derived*>(&d)); 47 test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d)); 48 test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d)); 49 test<Base*>(&d); 50 #if TEST_STD_VER > 14 51 { 52 using BaseIter = std::move_iterator<const Base *>; 53 using DerivedIter = std::move_iterator<const Derived *>; 54 constexpr const Derived *p = nullptr; 55 constexpr DerivedIter it1 = std::make_move_iterator(p); 56 constexpr BaseIter it2 = (BaseIter{nullptr} = it1); 57 static_assert(it2.base() == p, ""); 58 } 59 #endif 60 } 61