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

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