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