1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // Optimization for deque::iterators
13 // template <class InputIterator, class OutputIterator>
15 // move_backward(InputIterator first, InputIterator last, OutputIterator result);
20 #include "test_macros.h"
21 #include "test_iterators.h"
22 #include "min_allocator.h"
26 make(int size
, int start
= 0 )
28 const int b
= 4096 / sizeof(int);
32 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
37 for (int i
= 0; i
< init
-start
; ++i
)
39 for (int i
= 0; i
< size
; ++i
)
41 for (int i
= 0; i
< start
; ++i
)
47 void testN(int start
, int N
)
49 typedef typename
C::iterator I
;
50 typedef typename
C::const_iterator CI
;
51 typedef random_access_iterator
<I
> RAI
;
52 typedef random_access_iterator
<CI
> RACI
;
53 C c1
= make
<C
>(N
, start
);
55 assert(std::move_backward(c1
.cbegin(), c1
.cend(), c2
.end()) == c2
.begin());
57 assert(std::move_backward(c2
.cbegin(), c2
.cend(), c1
.end()) == c1
.begin());
59 assert(std::move_backward(c1
.cbegin(), c1
.cend(), RAI(c2
.end())) == RAI(c2
.begin()));
61 assert(std::move_backward(c2
.cbegin(), c2
.cend(), RAI(c1
.end())) == RAI(c1
.begin()));
63 assert(std::move_backward(RACI(c1
.cbegin()), RACI(c1
.cend()), c2
.end()) == c2
.begin());
65 assert(std::move_backward(RACI(c2
.cbegin()), RACI(c2
.cend()), c1
.end()) == c1
.begin());
72 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
73 const int N
= sizeof(rng
)/sizeof(rng
[0]);
74 for (int i
= 0; i
< N
; ++i
)
75 for (int j
= 0; j
< N
; ++j
)
76 testN
<std::deque
<int> >(rng
[i
], rng
[j
]);
78 #if TEST_STD_VER >= 11
80 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
81 const int N
= sizeof(rng
)/sizeof(rng
[0]);
82 for (int i
= 0; i
< N
; ++i
)
83 for (int j
= 0; j
< N
; ++j
)
84 testN
<std::deque
<int, min_allocator
<int> > >(rng
[i
], rng
[j
]);