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 // UNSUPPORTED: c++03, c++11, c++14 11 12 // template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 13 // deque(InputIterator, InputIterator, Allocator = Allocator()) 14 // -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; 15 // 16 17 #include <deque> 18 #include <iterator> 19 #include <cassert> 20 #include <cstddef> 21 #include <climits> // INT_MAX 22 23 #include "test_macros.h" 24 #include "test_iterators.h" 25 #include "test_allocator.h" 26 27 struct A {}; 28 29 int main(int, char**) 30 { 31 32 // Test the explicit deduction guides 33 { 34 const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 35 std::deque deq(std::begin(arr), std::end(arr)); 36 37 static_assert(std::is_same_v<decltype(deq), std::deque<int>>, ""); 38 assert(std::equal(deq.begin(), deq.end(), std::begin(arr), std::end(arr))); 39 } 40 41 { 42 const long arr[] = {INT_MAX, 1L, 2L, 3L }; 43 std::deque deq(std::begin(arr), std::end(arr), std::allocator<long>()); 44 static_assert(std::is_same_v<decltype(deq)::value_type, long>, ""); 45 assert(deq.size() == 4); 46 assert(deq[0] == INT_MAX); 47 assert(deq[1] == 1L); 48 assert(deq[2] == 2L); 49 } 50 51 // Test the implicit deduction guides 52 53 { 54 // We don't expect this one to work. 55 // std::deque deq(std::allocator<int>()); // deque (allocator &) 56 } 57 58 { 59 std::deque deq(1, A{}); // deque (size_type, T) 60 static_assert(std::is_same_v<decltype(deq)::value_type, A>, ""); 61 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<A>>, ""); 62 assert(deq.size() == 1); 63 } 64 65 { 66 std::deque deq(1, A{}, test_allocator<A>()); // deque (size_type, T, allocator) 67 static_assert(std::is_same_v<decltype(deq)::value_type, A>, ""); 68 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<A>>, ""); 69 assert(deq.size() == 1); 70 } 71 72 { 73 std::deque deq{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list) 74 static_assert(std::is_same_v<decltype(deq)::value_type, unsigned>, ""); 75 assert(deq.size() == 5); 76 assert(deq[2] == 3U); 77 } 78 79 { 80 std::deque deq({1.0, 2.0, 3.0, 4.0}, test_allocator<double>()); // deque(initializer-list, allocator) 81 static_assert(std::is_same_v<decltype(deq)::value_type, double>, ""); 82 static_assert(std::is_same_v<decltype(deq)::allocator_type, test_allocator<double>>, ""); 83 assert(deq.size() == 4); 84 assert(deq[3] == 4.0); 85 } 86 87 { 88 std::deque<long double> source; 89 std::deque deq(source); // deque(deque &) 90 static_assert(std::is_same_v<decltype(deq)::value_type, long double>, ""); 91 static_assert(std::is_same_v<decltype(deq)::allocator_type, std::allocator<long double>>, ""); 92 assert(deq.size() == 0); 93 } 94 95 { 96 typedef test_allocator<short> Alloc; 97 typedef test_allocator<int> ConvertibleToAlloc; 98 99 { 100 std::deque<short, Alloc> source; 101 std::deque deq(source, Alloc(2)); 102 static_assert(std::is_same_v<decltype(deq), decltype(source)>); 103 } 104 105 { 106 std::deque<short, Alloc> source; 107 std::deque deq(source, ConvertibleToAlloc(2)); 108 static_assert(std::is_same_v<decltype(deq), decltype(source)>); 109 } 110 111 { 112 std::deque<short, Alloc> source; 113 std::deque deq(std::move(source), Alloc(2)); 114 static_assert(std::is_same_v<decltype(deq), decltype(source)>); 115 } 116 117 { 118 std::deque<short, Alloc> source; 119 std::deque deq(std::move(source), ConvertibleToAlloc(2)); 120 static_assert(std::is_same_v<decltype(deq), decltype(source)>); 121 } 122 } 123 124 return 0; 125 } 126