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#include <iterator> 17#include <cassert> 18#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 19#include <memory> 20#endif 21 22class A 23{ 24 int data_; 25public: 26 A() : data_(1) {} 27 ~A() {data_ = -1;} 28 29 friend bool operator==(const A& x, const A& y) 30 {return x.data_ == y.data_;} 31}; 32 33template <class It> 34void 35test(It i, typename std::iterator_traits<It>::value_type x) 36{ 37 std::move_iterator<It> r(i); 38 assert(*r == x); 39 typename std::iterator_traits<It>::value_type x2 = *r; 40 assert(x2 == x); 41} 42 43#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 44 45struct do_nothing 46{ 47 void operator()(void*) const {} 48}; 49 50#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 51 52int main() 53{ 54 A a; 55 test(&a, A()); 56#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 57 int i; 58 std::unique_ptr<int, do_nothing> p(&i); 59 test(&p, std::unique_ptr<int, do_nothing>(&i)); 60#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 61} 62