| 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 | // template <class InputIterator> deque(InputIterator f, InputIterator l); |
| 12 | |
| 13 | #include "asan_testing.h" |
| 14 | #include <deque> |
| 15 | #include <cassert> |
| 16 | #include <cstddef> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "test_allocator.h" |
| 20 | #include "test_iterators.h" |
| 21 | #include "min_allocator.h" |
| 22 | #if TEST_STD_VER >= 11 |
| 23 | # include "emplace_constructible.h" |
| 24 | #endif |
| 25 | |
| 26 | template <class InputIterator> |
| 27 | void test(InputIterator f, InputIterator l) { |
| 28 | typedef typename std::iterator_traits<InputIterator>::value_type T; |
| 29 | typedef std::allocator<T> Allocator; |
| 30 | typedef std::deque<T, Allocator> C; |
| 31 | typedef typename C::const_iterator const_iterator; |
| 32 | C d(f, l); |
| 33 | assert(d.size() == static_cast<std::size_t>(std::distance(f, l))); |
| 34 | assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); |
| 35 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
| 36 | for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) |
| 37 | assert(*i == *f); |
| 38 | } |
| 39 | |
| 40 | template <class Allocator, class InputIterator> |
| 41 | void test(InputIterator f, InputIterator l) { |
| 42 | typedef typename std::iterator_traits<InputIterator>::value_type T; |
| 43 | typedef std::deque<T, Allocator> C; |
| 44 | typedef typename C::const_iterator const_iterator; |
| 45 | C d(f, l); |
| 46 | assert(d.size() == static_cast<std::size_t>(std::distance(f, l))); |
| 47 | assert(static_cast<std::size_t>(std::distance(d.begin(), d.end())) == d.size()); |
| 48 | LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(d)); |
| 49 | for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) |
| 50 | assert(*i == *f); |
| 51 | } |
| 52 | |
| 53 | void basic_test() { |
| 54 | int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; |
| 55 | int* an = ab + sizeof(ab) / sizeof(ab[0]); |
| 56 | test(cpp17_input_iterator<const int*>(ab), cpp17_input_iterator<const int*>(an)); |
| 57 | test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an)); |
| 58 | test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an)); |
| 59 | test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an)); |
| 60 | test<limited_allocator<int, 4096> >(ab, an); |
| 61 | #if TEST_STD_VER >= 11 |
| 62 | test<min_allocator<int> >(ab, an); |
| 63 | #endif |
| 64 | } |
| 65 | |
| 66 | void test_emplacable_concept() { |
| 67 | #if TEST_STD_VER >= 11 |
| 68 | int arr1[] = {42}; |
| 69 | int arr2[] = {1, 101, 42}; |
| 70 | { |
| 71 | using T = EmplaceConstructibleAndMoveable<int>; |
| 72 | using It = random_access_iterator<int*>; |
| 73 | { |
| 74 | std::deque<T> v(It(arr1), It(std::end(arr1))); |
| 75 | assert(v[0].value == 42); |
| 76 | } |
| 77 | { |
| 78 | std::deque<T> v(It(arr2), It(std::end(arr2))); |
| 79 | assert(v[0].value == 1); |
| 80 | assert(v[1].value == 101); |
| 81 | assert(v[2].value == 42); |
| 82 | } |
| 83 | } |
| 84 | { |
| 85 | using T = EmplaceConstructibleAndMoveable<int>; |
| 86 | using It = cpp17_input_iterator<int*>; |
| 87 | { |
| 88 | std::deque<T> v(It(arr1), It(std::end(arr1))); |
| 89 | assert(v[0].copied == 0); |
| 90 | assert(v[0].value == 42); |
| 91 | } |
| 92 | { |
| 93 | std::deque<T> v(It(arr2), It(std::end(arr2))); |
| 94 | //assert(v[0].copied == 0); |
| 95 | assert(v[0].value == 1); |
| 96 | //assert(v[1].copied == 0); |
| 97 | assert(v[1].value == 101); |
| 98 | assert(v[2].copied == 0); |
| 99 | assert(v[2].value == 42); |
| 100 | } |
| 101 | } |
| 102 | #endif |
| 103 | } |
| 104 | |
| 105 | int main(int, char**) { |
| 106 | basic_test(); |
| 107 | test_emplacable_concept(); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |