mclow.lists created this revision. mclow.lists added a reviewer: EricWF. Based off of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0433r2.html
https://reviews.llvm.org/D46975 Files: include/deque test/std/containers/sequences/deque/deque.cons/deduct.pass.cpp 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,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <array> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// XFAIL: libcpp-no-deduction-guides + + +// template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> +// deque(InputIterator, InputIterator, Allocator = Allocator()) +// -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; +// + + +#include <deque> +#include <iterator> +#include <cassert> +#include <cstddef> +#include <climits> // INT_MAX + +#include "test_macros.h" +#include "test_iterators.h" + + +int main() +{ + + { + 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<decltype(deq), std::deque<int>>, ""); + 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<long>()); + static_assert(std::is_same_v<decltype(deq)::value_type, long>, ""); + assert(deq.size() == 4); + assert(deq[0] == INT_MAX); + assert(deq[1] == 1L + INT_MAX); + assert(deq[2] == 2L); + } +} Index: include/deque =================================================================== --- include/deque +++ include/deque @@ -128,6 +128,10 @@ void clear() noexcept; }; +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + deque(InputIterator, InputIterator, Allocator = Allocator()) + -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; + template <class T, class Allocator> bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> @@ -1461,6 +1465,23 @@ void __move_assign(deque& __c, false_type); }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator, _Alloc) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + + template <class _Tp, class _Allocator> 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,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <array> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// XFAIL: libcpp-no-deduction-guides + + +// template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> +// deque(InputIterator, InputIterator, Allocator = Allocator()) +// -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; +// + + +#include <deque> +#include <iterator> +#include <cassert> +#include <cstddef> +#include <climits> // INT_MAX + +#include "test_macros.h" +#include "test_iterators.h" + + +int main() +{ + + { + 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<decltype(deq), std::deque<int>>, ""); + 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<long>()); + static_assert(std::is_same_v<decltype(deq)::value_type, long>, ""); + assert(deq.size() == 4); + assert(deq[0] == INT_MAX); + assert(deq[1] == 1L + INT_MAX); + assert(deq[2] == 2L); + } +} Index: include/deque =================================================================== --- include/deque +++ include/deque @@ -128,6 +128,10 @@ void clear() noexcept; }; +template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> + deque(InputIterator, InputIterator, Allocator = Allocator()) + -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; + template <class T, class Allocator> bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> @@ -1461,6 +1465,23 @@ void __move_assign(deque& __c, false_type); }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; + +template<class _InputIterator, + class _Alloc, + class = typename enable_if<__is_allocator<_Alloc>::value, void>::type + > +deque(_InputIterator, _InputIterator, _Alloc) + -> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>; +#endif + + template <class _Tp, class _Allocator> deque<_Tp, _Allocator>::deque(size_type __n) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits