From ab04aadaf4e8ef81a2ebea176689c40333cb015e Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 7 Sep 2013 16:16:19 +0000 Subject: [PATCH] LWG Issue 2210 (Part #1): deque git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@190251 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/deque | 14 +++++ .../sequences/deque/deque.cons/size.pass.cpp | 58 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/include/deque b/include/deque index 4faa87f8b..5bb8ff7a8 100644 --- a/include/deque +++ b/include/deque @@ -41,6 +41,7 @@ public: deque() noexcept(is_nothrow_default_constructible::value); explicit deque(const allocator_type& a); explicit deque(size_type n); + explicit deque(size_type n, const Allocator& a); // C++14 deque(size_type n, const value_type& v); deque(size_type n, const value_type& v, const allocator_type& a); template @@ -1209,6 +1210,9 @@ public: {} _LIBCPP_INLINE_VISIBILITY deque(const allocator_type& __a) : __base(__a) {} explicit deque(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit deque(size_type __n, const _Allocator& __a); +#endif deque(size_type __n, const value_type& __v); deque(size_type __n, const value_type& __v, const allocator_type& __a); template @@ -1431,6 +1435,16 @@ deque<_Tp, _Allocator>::deque(size_type __n) __append(__n); } +#if _LIBCPP_STD_VER > 11 +template +deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) + : __base(__a) +{ + if (__n > 0) + __append(__n); +} +#endif + template deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) { diff --git a/test/containers/sequences/deque/deque.cons/size.pass.cpp b/test/containers/sequences/deque/deque.cons/size.pass.cpp index 6d0bf4248..1f07caf48 100644 --- a/test/containers/sequences/deque/deque.cons/size.pass.cpp +++ b/test/containers/sequences/deque/deque.cons/size.pass.cpp @@ -20,7 +20,29 @@ template void -test(unsigned n) +test2(unsigned n) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + assert(DefaultOnly::count == 0); + { + C d(n, Allocator()); + assert(DefaultOnly::count == n); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(DefaultOnly::count == 0); +#endif +} + +template +void +test1(unsigned n) { typedef std::deque C; typedef typename C::const_iterator const_iterator; @@ -38,6 +60,29 @@ test(unsigned n) assert(DefaultOnly::count == 0); } +template +void +test3(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + { + C d(n, alloc); + assert(d.size() == n); + assert(d.get_allocator() == alloc); + } +#endif +} + +template +void +test(unsigned n) +{ + test1 ( n ); + test2 ( n ); +} + int main() { test >(0); @@ -52,8 +97,17 @@ int main() test >(4095); test >(4096); test >(4097); - test >(4095); + + test1 >(4095); + #if __cplusplus >= 201103L test >(4095); #endif + +#if _LIBCPP_STD_VER > 11 + test3> (1023); + test3>(1); + test3> (3); +#endif + }