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 // reference operator*() const; 15 // 16 // constexpr in C++17 17 18 #include <iterator> 19 #include <cassert> 20 #include <memory> 21 22 #include "test_macros.h" 23 24 class A 25 { 26 int data_; 27 public: 28 A() : data_(1) {} 29 ~A() {data_ = -1;} 30 31 friend bool operator==(const A& x, const A& y) 32 {return x.data_ == y.data_;} 33 }; 34 35 template <class It> 36 void 37 test(It i, typename std::iterator_traits<It>::value_type x) 38 { 39 std::move_iterator<It> r(i); 40 assert(*r == x); 41 typename std::iterator_traits<It>::value_type x2 = *r; 42 assert(x2 == x); 43 } 44 45 struct do_nothing 46 { 47 void operator()(void*) const {} 48 }; 49 50 51 int main() 52 { 53 { 54 A a; 55 test(&a, A()); 56 } 57 #if TEST_STD_VER >= 11 58 { 59 int i; 60 std::unique_ptr<int, do_nothing> p(&i); 61 test(&p, std::unique_ptr<int, do_nothing>(&i)); 62 } 63 #endif 64 #if TEST_STD_VER > 14 65 { 66 constexpr const char *p = "123456789"; 67 typedef std::move_iterator<const char *> MI; 68 constexpr MI it1 = std::make_move_iterator(p); 69 constexpr MI it2 = std::make_move_iterator(p+1); 70 static_assert(*it1 == p[0], ""); 71 static_assert(*it2 == p[1], ""); 72 } 73 #endif 74 } 75