[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.cons / iter_iter_alloc.pass.cpp
blobc72f73a9a8a2bbab213d9333d776ed48fa306731
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>
12 // deque(InputIterator f, InputIterator l, const allocator_type& a);
14 #include <deque>
15 #include <cassert>
16 #include <cstddef>
18 #include "test_macros.h"
19 #include "test_iterators.h"
20 #include "test_allocator.h"
21 #include "min_allocator.h"
22 #if TEST_STD_VER >= 11
23 #include "emplace_constructible.h"
24 #endif
26 template <class InputIterator, class Allocator>
27 void
28 test(InputIterator f, InputIterator l, const Allocator& a)
30 typedef typename std::iterator_traits<InputIterator>::value_type T;
31 typedef std::deque<T, Allocator> C;
32 typedef typename C::const_iterator const_iterator;
33 C d(f, l, a);
34 assert(d.get_allocator() == a);
35 assert(d.size() == static_cast<std::size_t>(std::distance(f, l)));
36 assert(static_cast<std::size_t>(distance(d.begin(), d.end())) == d.size());
37 for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f)
38 assert(*i == *f);
41 void basic_test()
43 int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
44 int* an = ab + sizeof(ab)/sizeof(ab[0]);
45 test(input_iterator<const int*>(ab), input_iterator<const int*>(an), test_allocator<int>(3));
46 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), test_allocator<int>(4));
47 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), test_allocator<int>(5));
48 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), test_allocator<int>(6));
49 #if TEST_STD_VER >= 11
50 test(input_iterator<const int*>(ab), input_iterator<const int*>(an), min_allocator<int>());
51 test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), min_allocator<int>());
52 test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), min_allocator<int>());
53 test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), min_allocator<int>());
54 #endif
58 void test_emplacable_concept() {
59 #if TEST_STD_VER >= 11
60 int arr1[] = {42};
61 int arr2[] = {1, 101, 42};
63 using T = EmplaceConstructibleAndMoveable<int>;
64 using It = random_access_iterator<int*>;
65 std::allocator<T> a;
67 std::deque<T> v(It(arr1), It(std::end(arr1)), a);
68 assert(v[0].value == 42);
71 std::deque<T> v(It(arr2), It(std::end(arr2)), a);
72 assert(v[0].value == 1);
73 assert(v[1].value == 101);
74 assert(v[2].value == 42);
78 using T = EmplaceConstructibleAndMoveable<int>;
79 using It = input_iterator<int*>;
80 std::allocator<T> a;
82 std::deque<T> v(It(arr1), It(std::end(arr1)), a);
83 assert(v[0].copied == 0);
84 assert(v[0].value == 42);
87 std::deque<T> v(It(arr2), It(std::end(arr2)), a);
88 //assert(v[0].copied == 0);
89 assert(v[0].value == 1);
90 //assert(v[1].copied == 0);
91 assert(v[1].value == 101);
92 assert(v[2].copied == 0);
93 assert(v[2].value == 42);
96 #endif
99 int main(int, char**) {
100 basic_test();
101 test_emplacable_concept();
103 return 0;