diff --git a/include/vector b/include/vector index e4fc024d..258a950d 100644 --- a/include/vector +++ b/include/vector @@ -38,6 +38,7 @@ public: noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); explicit vector(size_type n); + explicit vector(size_type n, const allocator_type&); // C++14 vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); template vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); @@ -161,7 +162,8 @@ public: vector() noexcept(is_nothrow_default_constructible::value); explicit vector(const allocator_type&); - explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type()); + explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 + vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); template vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); vector(const vector& x); @@ -516,6 +518,9 @@ public: #endif } explicit vector(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit vector(size_type __n, const allocator_type& __a); +#endif vector(size_type __n, const_reference __x); vector(size_type __n, const_reference __x, const allocator_type& __a); template @@ -1022,6 +1027,22 @@ vector<_Tp, _Allocator>::vector(size_type __n) } } +#if _LIBCPP_STD_VER > 11 +template +vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) + : __base(__a) +{ +#if _LIBCPP_DEBUG_LEVEL >= 2 + __get_db()->__insert_c(this); +#endif + if (__n > 0) + { + allocate(__n); + __construct_at_end(__n); + } +} +#endif + template vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x) { @@ -2079,6 +2100,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a); ~vector(); explicit vector(size_type __n); +#if _LIBCPP_STD_VER > 11 + explicit vector(size_type __n, const allocator_type& __a); +#endif vector(size_type __n, const value_type& __v); vector(size_type __n, const value_type& __v, const allocator_type& __a); template @@ -2489,6 +2513,21 @@ vector::vector(size_type __n) } } +#if _LIBCPP_STD_VER > 11 +template +vector::vector(size_type __n, const allocator_type& __a) + : __begin_(nullptr), + __size_(0), + __cap_alloc_(0, static_cast<__storage_allocator>(__a)) +{ + if (__n > 0) + { + allocate(__n); + __construct_at_end(__n, false); + } +} +#endif + template vector::vector(size_type __n, const value_type& __x) : __begin_(nullptr), diff --git a/test/containers/sequences/vector.bool/construct_size.pass.cpp b/test/containers/sequences/vector.bool/construct_size.pass.cpp index 0bbd3627..aa4ca0e2 100644 --- a/test/containers/sequences/vector.bool/construct_size.pass.cpp +++ b/test/containers/sequences/vector.bool/construct_size.pass.cpp @@ -16,10 +16,27 @@ #include #include "../../min_allocator.h" +#include "../../test_allocator.h" template void -test(typename C::size_type n) +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template +void +test1(typename C::size_type n) { C c(n); assert(c.__invariants()); @@ -29,10 +46,19 @@ test(typename C::size_type n) assert(*i == typename C::value_type()); } +template +void +test(typename C::size_type n) +{ + test1 ( n ); + test2 ( n ); +} + int main() { test >(50); #if __cplusplus >= 201103L test> >(50); + test2> >( 100, test_allocator(23)); #endif } diff --git a/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp index c49b6686..19d27602 100644 --- a/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp +++ b/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp @@ -16,10 +16,27 @@ #include "../../../DefaultOnly.h" #include "../../../min_allocator.h" +#include "../../../test_allocator.h" template void -test(typename C::size_type n) +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template +void +test1(typename C::size_type n) { C c(n); assert(c.__invariants()); @@ -31,6 +48,14 @@ test(typename C::size_type n) #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } +template +void +test(typename C::size_type n) +{ + test1 ( n ); + test2 ( n ); +} + int main() { test >(50); @@ -39,6 +64,7 @@ int main() #if __cplusplus >= 201103L test> >(50); test> >(500); + test2> >( 100, test_allocator(23)); assert(DefaultOnly::count == 0); #endif }