[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.cons / iter_iter.pass.cpp
blob214ac8303bd73f52e6cc5e5379896e73b49250f7
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 //===----------------------------------------------------------------------===//
9 // <deque>
11 // template <class InputIterator> deque(InputIterator f, InputIterator l);
13 #include <deque>
14 #include <cassert>
15 #include <cstddef>
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "test_iterators.h"
20 #include "min_allocator.h"
21 #if TEST_STD_VER >= 11
22 #include "emplace_constructible.h"
23 #endif
25 template <class InputIterator>
26 void
27 test(InputIterator f, InputIterator l)
29 typedef typename std::iterator_traits<InputIterator>::value_type T;
30 typedef std::allocator<T> Allocator;
31 typedef std::deque<T, Allocator> C;
32 typedef typename C::const_iterator const_iterator;
33 C d(f, l);
34 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
35 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
36 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
37 assert(*i == *f);
40 template <class Allocator, class InputIterator>
41 void
42 test(InputIterator f, InputIterator l)
44 typedef typename std::iterator_traits<InputIterator>::value_type T;
45 typedef std::deque<T, Allocator> C;
46 typedef typename C::const_iterator const_iterator;
47 C d(f, l);
48 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
49 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
50 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
51 assert(*i == *f);
54 void basic_test()
56 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
57 int* an = ab + sizeof(ab)/sizeof(ab[0]);
58 test(input_iterator<const int*>(ab), input_iterator<const int*>(an));
59 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an));
60 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an));
61 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an));
62 test<limited_allocator<int, 4096> >(ab, an);
63 #if TEST_STD_VER >= 11
64 test<min_allocator<int> >(ab, an);
65 #endif
69 void test_emplacable_concept() {
70 #if TEST_STD_VER >= 11
71 int arr1[] = {42};
72 int arr2[] = {1, 101, 42};
74 using T = EmplaceConstructibleAndMoveable<int>;
75 using It = random_access_iterator<int*>;
77 std::deque<T> v(It(arr1), It(std::end(arr1)));
78 assert(v[0].value == 42);
81 std::deque<T> v(It(arr2), It(std::end(arr2)));
82 assert(v[0].value == 1);
83 assert(v[1].value == 101);
84 assert(v[2].value == 42);
88 using T = EmplaceConstructibleAndMoveable<int>;
89 using It = input_iterator<int*>;
91 std::deque<T> v(It(arr1), It(std::end(arr1)));
92 assert(v[0].copied == 0);
93 assert(v[0].value == 42);
96 std::deque<T> v(It(arr2), It(std::end(arr2)));
97 //assert(v[0].copied == 0);
98 assert(v[0].value == 1);
99 //assert(v[1].copied == 0);
100 assert(v[1].value == 101);
101 assert(v[2].copied == 0);
102 assert(v[2].value == 42);
105 #endif
108 int main(int, char**) {
109 basic_test();
110 test_emplacable_concept();
112 return 0;