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