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