Index: include/deque =================================================================== --- include/deque +++ include/deque @@ -128,6 +128,10 @@ void clear() noexcept; }; +template ::value_type>> + deque(InputIterator, InputIterator, Allocator = Allocator()) + -> deque::value_type, Allocator>; + template bool operator==(const deque& x, const deque& y); template @@ -921,13 +925,14 @@ { __deque_base(const __deque_base& __c); __deque_base& operator=(const __deque_base& __c); +public: + typedef _Allocator allocator_type; + typedef allocator_traits __alloc_traits; + typedef typename __alloc_traits::size_type size_type; protected: typedef _Tp value_type; - typedef _Allocator allocator_type; - typedef allocator_traits __alloc_traits; typedef value_type& reference; typedef const value_type& const_reference; - typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; @@ -946,6 +951,7 @@ typedef __deque_iterator const_iterator; +protected: __map __map_; size_type __start_; __compressed_pair __size_; @@ -1461,6 +1467,23 @@ void __move_assign(deque& __c, false_type); }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator) + -> deque::value_type, _Alloc>; + +template::value, void>::type + > +deque(_InputIterator, _InputIterator, _Alloc) + -> deque::value_type, _Alloc>; +#endif + + template deque<_Tp, _Allocator>::deque(size_type __n) { Index: test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp =================================================================== --- test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp +++ test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// XFAIL: libcpp-no-deduction-guides + + +// template ::value_type>> +// deque(InputIterator, InputIterator, Allocator = Allocator()) +// -> deque::value_type, Allocator>; +// + + +#include +#include +#include +#include +#include // INT_MAX + +#include "test_macros.h" +#include "test_iterators.h" +#include "test_allocator.h" + +struct A {}; + +int main() +{ + +// Test the explicit deduction guides + { + const int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::deque deq(std::begin(arr), std::end(arr)); + + static_assert(std::is_same_v>, ""); + assert(std::equal(deq.begin(), deq.end(), std::begin(arr), std::end(arr))); + } + + { + const long arr[] = {INT_MAX, 1L + INT_MAX, 2L, 3L }; + std::deque deq(std::begin(arr), std::end(arr), std::allocator()); + static_assert(std::is_same_v, ""); + assert(deq.size() == 4); + assert(deq[0] == INT_MAX); + assert(deq[1] == 1L + INT_MAX); + assert(deq[2] == 2L); + } + +// Test the implicit deduction guides + + { +// We don't expect this one to work. +// std::deque deq(std::allocator()); // deque (allocator &) + } + + { + std::deque deq(1, A{}); // deque (size_type, T) + static_assert(std::is_same_v, ""); + static_assert(std::is_same_v>, ""); + assert(deq.size() == 1); + } + + { + std::deque deq(1, A{}, test_allocator()); // deque (size_type, T, allocator) + static_assert(std::is_same_v, ""); + static_assert(std::is_same_v>, ""); + assert(deq.size() == 1); + } + + { + std::deque deq{1U, 2U, 3U, 4U, 5U}; // deque(initializer-list) + static_assert(std::is_same_v, ""); + assert(deq.size() == 5); + assert(deq[2] == 3U); + } + + { + std::deque deq({1.0, 2.0, 3.0, 4.0}, test_allocator()); // deque(initializer-list, allocator) + static_assert(std::is_same_v, ""); + static_assert(std::is_same_v>, ""); + assert(deq.size() == 4); + assert(deq[3] == 4.0); + } + + { + std::deque source; + std::deque deq(source); // deque(deque &) + static_assert(std::is_same_v, ""); + static_assert(std::is_same_v>, ""); + assert(deq.size() == 0); + } +}