[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.cons / deduct.pass.cpp
blob1a143819106e7ba22b3f37dd2cda1bc75303ac16
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 // <array>
10 // UNSUPPORTED: c++03, c++11, c++14
11 // UNSUPPORTED: libcpp-no-deduction-guides
14 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
15 // deque(InputIterator, InputIterator, Allocator = Allocator())
16 // -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
20 #include <deque>
21 #include <iterator>
22 #include <cassert>
23 #include <cstddef>
24 #include <climits> // INT_MAX
26 #include "test_macros.h"
27 #include "test_iterators.h"
28 #include "test_allocator.h"
30 struct A {};
32 int main(int, char**)
35 // Test the explicit deduction guides
37 const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
38 std::deque deq(std::begin(arr), std::end(arr));
40 static_assert(std::is_same_v<decltype(deq), std::deque<int>>, "");
41 assert(std::equal(deq.begin(), deq.end(), std::begin(arr), std::end(arr)));
45 const long arr[] = {INT_MAX, 1L, 2L, 3L };
46 std::deque deq(std::begin(arr), std::end(arr), std::allocator<long>());
47 static_assert(std::is_same_v<decltype(deq)::value_type, long>, "");
48 assert(deq.size() == 4);
49 assert(deq[0] == INT_MAX);
50 assert(deq[1] == 1L);
51 assert(deq[2] == 2L);
54 // Test the implicit deduction guides
57 // We don't expect this one to work.
58 // std::deque deq(std::allocator<int>()); // deque (allocator &)
62 std::deque deq(1, A{}); // deque (size_type, T)
63 static_assert(std::is_same_v<decltype(deq)::value_type, A>, "");
64 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<A>>, "");
65 assert(deq.size() == 1);
69 std::deque deq(1, A{}, test_allocator<A>()); // deque (size_type, T, allocator)
70 static_assert(std::is_same_v<decltype(deq)::value_type, A>, "");
71 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<A>>, "");
72 assert(deq.size() == 1);
76 std::deque deq{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list)
77 static_assert(std::is_same_v<decltype(deq)::value_type, unsigned>, "");
78 assert(deq.size() == 5);
79 assert(deq[2] == 3U);
83 std::deque deq({1.0, 2.0, 3.0, 4.0}, test_allocator<double>()); // deque(initializer-list, allocator)
84 static_assert(std::is_same_v<decltype(deq)::value_type, double>, "");
85 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<double>>, "");
86 assert(deq.size() == 4);
87 assert(deq[3] == 4.0);
91 std::deque<long double> source;
92 std::deque deq(source); // deque(deque &)
93 static_assert(std::is_same_v<decltype(deq)::value_type, long double>, "");
94 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<long double>>, "");
95 assert(deq.size() == 0);
98 return 0;