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 // template <RandomAccessIterator Iter>
14 // move_iterator<Iter>
15 // operator+(Iter::difference_type n, const move_iterator<Iter>& x);
16 //
17 // constexpr in C++17
18
19 #include <iterator>
20 #include <cassert>
21
22 #include "test_macros.h"
23 #include "test_iterators.h"
24
25 template <class It>
26 void
test(It i,typename std::iterator_traits<It>::difference_type n,It x)27 test(It i, typename std::iterator_traits<It>::difference_type n, It x)
28 {
29 const std::move_iterator<It> r(i);
30 std::move_iterator<It> rr = n + r;
31 assert(rr.base() == x);
32 }
33
main(int,char **)34 int main(int, char**)
35 {
36 char s[] = "1234567890";
37 test(random_access_iterator<char*>(s+5), 5, random_access_iterator<char*>(s+10));
38 test(s+5, 5, s+10);
39
40 #if TEST_STD_VER > 14
41 {
42 constexpr const char *p = "123456789";
43 typedef std::move_iterator<const char *> MI;
44 constexpr MI it1 = std::make_move_iterator(p);
45 constexpr MI it2 = std::make_move_iterator(p + 5);
46 constexpr MI it3 = it1 + 5;
47 static_assert(it1 != it2, "");
48 static_assert(it1 != it3, "");
49 static_assert(it2 == it3, "");
50 }
51 #endif
52
53 return 0;
54 }
55