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 // copy(InputIterator first, InputIterator last, OutputIterator result);
17 #include "asan_testing.h"
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 #include "min_allocator.h"
27 make(int size
, int start
= 0 )
29 const int b
= 4096 / sizeof(int);
33 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
38 for (int i
= 0; i
< init
-start
; ++i
)
40 for (int i
= 0; i
< size
; ++i
)
42 for (int i
= 0; i
< start
; ++i
)
48 void testN(int start
, int N
)
50 typedef typename
C::iterator I
;
51 typedef typename
C::const_iterator CI
;
52 typedef random_access_iterator
<I
> RAI
;
53 typedef random_access_iterator
<CI
> RACI
;
54 typedef cpp17_input_iterator
<CI
> ICI
;
55 C c1
= make
<C
>(N
, start
);
57 assert(std::copy(c1
.cbegin(), c1
.cend(), c2
.begin()) == c2
.end());
59 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
60 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
61 assert(std::copy(c2
.cbegin(), c2
.cend(), c1
.begin()) == c1
.end());
63 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
64 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
65 assert(std::copy(c1
.cbegin(), c1
.cend(), RAI(c2
.begin())) == RAI(c2
.end()));
67 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
68 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
69 assert(std::copy(c2
.cbegin(), c2
.cend(), RAI(c1
.begin())) == RAI(c1
.end()));
71 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
72 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
73 assert(std::copy(RACI(c1
.cbegin()), RACI(c1
.cend()), c2
.begin()) == c2
.end());
75 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
76 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
77 assert(std::copy(ICI(c2
.cbegin()), ICI(c2
.cend()), c1
.begin()) == c1
.end());
79 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1
));
80 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c2
));
86 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
87 const int N
= sizeof(rng
)/sizeof(rng
[0]);
88 for (int i
= 0; i
< N
; ++i
)
89 for (int j
= 0; j
< N
; ++j
)
90 testN
<std::deque
<int> >(rng
[i
], rng
[j
]);
92 #if TEST_STD_VER >= 11
94 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
95 const int N
= sizeof(rng
)/sizeof(rng
[0]);
96 for (int i
= 0; i
< N
; ++i
)
97 for (int j
= 0; j
< N
; ++j
)
98 testN
<std::deque
<int, min_allocator
<int>> >(rng
[i
], rng
[j
]);