| 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 | // <deque> |
| 10 | |
| 11 | // deque(size_type n, const value_type& v, const allocator_type& a); |
| 12 | |
| 13 | #include "asan_testing.h" |
| 14 | #include <deque> |
| 15 | #include <cassert> |
| 16 | #include <cstddef> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | template <class T, class Allocator> |
| 22 | void test(unsigned n, const T& x, const Allocator& a) { |
| 23 | typedef std::deque<T, Allocator> C; |
| 24 | typedef typename C::const_iterator const_iterator; |
| 25 | C d(n, x, a); |
| 26 | assert(d.get_allocator() == a); |
| 27 | assert(d.size() == n); |
| 28 | assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); |
| 29 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
| 30 | for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) |
| 31 | assert(*i == x); |
| 32 | } |
| 33 | |
| 34 | int main(int, char**) { |
| 35 | { |
| 36 | std::allocator<int> a; |
| 37 | test(n: 0, x: 5, a); |
| 38 | test(n: 1, x: 10, a); |
| 39 | test(n: 10, x: 11, a); |
| 40 | test(n: 1023, x: -11, a); |
| 41 | test(n: 1024, x: 25, a); |
| 42 | test(n: 1025, x: 0, a); |
| 43 | test(n: 2047, x: 110, a); |
| 44 | test(n: 2048, x: -500, a); |
| 45 | test(n: 2049, x: 654, a); |
| 46 | test(n: 4095, x: 78, a); |
| 47 | test(n: 4096, x: 1165, a); |
| 48 | test(n: 4097, x: 157, a); |
| 49 | } |
| 50 | #if TEST_STD_VER >= 11 |
| 51 | { |
| 52 | min_allocator<int> a; |
| 53 | test(0, 5, a); |
| 54 | test(1, 10, a); |
| 55 | test(10, 11, a); |
| 56 | test(1023, -11, a); |
| 57 | test(1024, 25, a); |
| 58 | test(1025, 0, a); |
| 59 | test(2047, 110, a); |
| 60 | test(2048, -500, a); |
| 61 | test(2049, 654, a); |
| 62 | test(4095, 78, a); |
| 63 | test(4096, 1165, a); |
| 64 | test(4097, 157, a); |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |