[libcxx] r190736 - LWG Issue 2210 (Part #7): vector and vector<bool>
Marshall Clow
mclow.lists at gmail.com
Fri Sep 13 17:47:59 PDT 2013
Author: marshall
Date: Fri Sep 13 19:47:59 2013
New Revision: 190736
URL: http://llvm.org/viewvc/llvm-project?rev=190736&view=rev
Log:
LWG Issue 2210 (Part #7): vector and vector<bool>
Modified:
libcxx/trunk/include/vector
libcxx/trunk/test/containers/sequences/vector.bool/construct_size.pass.cpp
libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp
Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=190736&r1=190735&r2=190736&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Fri Sep 13 19:47:59 2013
@@ -38,6 +38,7 @@ public:
noexcept(is_nothrow_default_constructible<allocator_type>::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 <class InputIterator>
vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
@@ -161,7 +162,8 @@ public:
vector()
noexcept(is_nothrow_default_constructible<allocator_type>::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 <class InputIterator>
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 <class _InputIterator>
@@ -1022,6 +1027,22 @@ vector<_Tp, _Allocator>::vector(size_typ
}
}
+#if _LIBCPP_STD_VER > 11
+template <class _Tp, class _Allocator>
+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 <class _Tp, class _Allocator>
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 <class _InputIterator>
@@ -2489,6 +2513,21 @@ vector<bool, _Allocator>::vector(size_ty
}
}
+#if _LIBCPP_STD_VER > 11
+template <class _Allocator>
+vector<bool, _Allocator>::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 <class _Allocator>
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
: __begin_(nullptr),
Modified: libcxx/trunk/test/containers/sequences/vector.bool/construct_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector.bool/construct_size.pass.cpp?rev=190736&r1=190735&r2=190736&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector.bool/construct_size.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector.bool/construct_size.pass.cpp Fri Sep 13 19:47:59 2013
@@ -16,10 +16,27 @@
#include <cassert>
#include "../../min_allocator.h"
+#include "../../test_allocator.h"
template <class C>
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 <class C>
+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 <class C>
+void
+test(typename C::size_type n)
+{
+ test1<C> ( n );
+ test2<C> ( n );
+}
+
int main()
{
test<std::vector<bool> >(50);
#if __cplusplus >= 201103L
test<std::vector<bool, min_allocator<bool>> >(50);
+ test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23));
#endif
}
Modified: libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp?rev=190736&r1=190735&r2=190736&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp Fri Sep 13 19:47:59 2013
@@ -16,10 +16,27 @@
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
+#include "../../../test_allocator.h"
template <class C>
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 <class C>
+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 <class C>
+void
+test(typename C::size_type n)
+{
+ test1<C> ( n );
+ test2<C> ( n );
+}
+
int main()
{
test<std::vector<int> >(50);
@@ -39,6 +64,7 @@ int main()
#if __cplusplus >= 201103L
test<std::vector<int, min_allocator<int>> >(50);
test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500);
+ test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23));
assert(DefaultOnly::count == 0);
#endif
}
More information about the cfe-commits
mailing list