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

source code of libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp