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 // Test nested types:
15
16 // template <InputIterator Iter>
17 // class move_iterator {
18 // public:
19 // typedef Iter iterator_type;
20 // typedef Iter::difference_type difference_type;
21 // typedef Iter pointer;
22 // typedef Iter::value_type value_type;
23 // typedef value_type&& reference;
24 // };
25
26 #include <iterator>
27 #include <type_traits>
28
29 #include "test_macros.h"
30 #include "test_iterators.h"
31
32 template <class ValueType, class Reference>
33 struct DummyIt {
34 typedef std::forward_iterator_tag iterator_category;
35 typedef ValueType value_type;
36 typedef std::ptrdiff_t difference_type;
37 typedef ValueType* pointer;
38 typedef Reference reference;
39 };
40
41 template <class It>
42 void
test()43 test()
44 {
45 typedef std::move_iterator<It> R;
46 typedef std::iterator_traits<It> T;
47 static_assert((std::is_same<typename R::iterator_type, It>::value), "");
48 static_assert((std::is_same<typename R::difference_type, typename T::difference_type>::value), "");
49 static_assert((std::is_same<typename R::pointer, It>::value), "");
50 static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
51 #if TEST_STD_VER >= 11
52 static_assert((std::is_same<typename R::reference, typename R::value_type&&>::value), "");
53 #else
54 static_assert((std::is_same<typename R::reference, typename T::reference>::value), "");
55 #endif
56 static_assert((std::is_same<typename R::iterator_category, typename T::iterator_category>::value), "");
57 }
58
main()59 int main()
60 {
61 test<input_iterator<char*> >();
62 test<forward_iterator<char*> >();
63 test<bidirectional_iterator<char*> >();
64 test<random_access_iterator<char*> >();
65 test<char*>();
66 #if TEST_STD_VER >= 11
67 {
68 typedef DummyIt<int, int> T;
69 typedef std::move_iterator<T> It;
70 static_assert(std::is_same<It::reference, int>::value, "");
71 }
72 {
73 typedef DummyIt<int, std::reference_wrapper<int> > T;
74 typedef std::move_iterator<T> It;
75 static_assert(std::is_same<It::reference, std::reference_wrapper<int> >::value, "");
76 }
77 {
78 // Check that move_iterator uses whatever reference type it's given
79 // when it's not a reference.
80 typedef DummyIt<int, long > T;
81 typedef std::move_iterator<T> It;
82 static_assert(std::is_same<It::reference, long>::value, "");
83 }
84 {
85 typedef DummyIt<int, int&> T;
86 typedef std::move_iterator<T> It;
87 static_assert(std::is_same<It::reference, int&&>::value, "");
88 }
89 {
90 typedef DummyIt<int, int&&> T;
91 typedef std::move_iterator<T> It;
92 static_assert(std::is_same<It::reference, int&&>::value, "");
93 }
94 #endif
95 }
96