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 | // explicit move_iterator(Iter i); |
14 | // |
15 | // constexpr in C++17 |
16 | |
17 | #include <iterator> |
18 | #include <cassert> |
19 | #include <utility> |
20 | |
21 | #include "test_macros.h" |
22 | #include "test_iterators.h" |
23 | |
24 | template <class It> |
25 | TEST_CONSTEXPR_CXX17 bool test() |
26 | { |
27 | static_assert( std::is_constructible<std::move_iterator<It>, const It&>::value, "" ); |
28 | static_assert( std::is_constructible<std::move_iterator<It>, It&&>::value, "" ); |
29 | static_assert(!std::is_convertible<const It&, std::move_iterator<It> >::value, "" ); |
30 | static_assert(!std::is_convertible<It&&, std::move_iterator<It> >::value, "" ); |
31 | |
32 | char s[] = "123" ; |
33 | { |
34 | It it = It(s); |
35 | std::move_iterator<It> r(it); |
36 | assert(base(r.base()) == s); |
37 | } |
38 | { |
39 | It it = It(s); |
40 | std::move_iterator<It> r(std::move(it)); |
41 | assert(base(r.base()) == s); |
42 | } |
43 | return true; |
44 | } |
45 | |
46 | template <class It> |
47 | TEST_CONSTEXPR_CXX17 bool test_moveonly() |
48 | { |
49 | static_assert(!std::is_constructible<std::move_iterator<It>, const It&>::value, "" ); |
50 | static_assert( std::is_constructible<std::move_iterator<It>, It&&>::value, "" ); |
51 | static_assert(!std::is_convertible<const It&, std::move_iterator<It> >::value, "" ); |
52 | static_assert(!std::is_convertible<It&&, std::move_iterator<It> >::value, "" ); |
53 | |
54 | char s[] = "123" ; |
55 | { |
56 | It it = It(s); |
57 | std::move_iterator<It> r(std::move(it)); |
58 | assert(base(r.base()) == s); |
59 | } |
60 | return true; |
61 | } |
62 | |
63 | int main(int, char**) |
64 | { |
65 | test<cpp17_input_iterator<char*> >(); |
66 | test<forward_iterator<char*> >(); |
67 | test<bidirectional_iterator<char*> >(); |
68 | test<random_access_iterator<char*> >(); |
69 | test<char*>(); |
70 | test<const char*>(); |
71 | |
72 | #if TEST_STD_VER > 14 |
73 | static_assert(test<cpp17_input_iterator<char*>>()); |
74 | static_assert(test<forward_iterator<char*>>()); |
75 | static_assert(test<bidirectional_iterator<char*>>()); |
76 | static_assert(test<random_access_iterator<char*>>()); |
77 | static_assert(test<char*>()); |
78 | static_assert(test<const char*>()); |
79 | #endif |
80 | |
81 | #if TEST_STD_VER > 17 |
82 | test<contiguous_iterator<char*>>(); |
83 | test_moveonly<cpp20_input_iterator<char*>>(); |
84 | static_assert(test<contiguous_iterator<char*>>()); |
85 | static_assert(test_moveonly<cpp20_input_iterator<char*>>()); |
86 | #endif |
87 | |
88 | return 0; |
89 | } |
90 | |