diff --git a/doc/container.qbk b/doc/container.qbk index 9e2972f..6e00214 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1219,6 +1219,7 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs: * [@https://svn.boost.org/trac/boost/ticket/11820 Trac #11820 : ['"compiler error when using operator[] of map"]]. * [@https://svn.boost.org/trac/boost/ticket/11856 Trac #11856 : ['"pool_resource.cpp error: declaration changes meaning"]]. + * [@https://svn.boost.org/trac/boost/ticket/11866 Trac #11866 : ['"small_vector does not have range constructor"]]. * [@https://svn.boost.org/trac/boost/ticket/11867 Trac #11867 : ['"small_vector should have constructor and assignment operator taking other small_vector"]]. * [@https://github.com/boostorg/container/pull/33 GitHub #33: ['Make sure std::string constructor is available]]. diff --git a/include/boost/container/small_vector.hpp b/include/boost/container/small_vector.hpp index 3713d93..14e398a 100644 --- a/include/boost/container/small_vector.hpp +++ b/include/boost/container/small_vector.hpp @@ -151,50 +151,58 @@ class small_vector_allocator //!Constructor from other small_vector_allocator. //!Never throws - BOOST_CONTAINER_FORCEINLINE small_vector_allocator(const small_vector_allocator &other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator + (const small_vector_allocator &other) BOOST_NOEXCEPT_OR_NOTHROW : Allocator(other.as_base()) {} //!Move constructor from small_vector_allocator. //!Never throws - BOOST_CONTAINER_FORCEINLINE small_vector_allocator(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator + (BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW : Allocator(::boost::move(other.as_base())) {} //!Constructor from related small_vector_allocator. //!Never throws template - BOOST_CONTAINER_FORCEINLINE small_vector_allocator(const small_vector_allocator &other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator + (const small_vector_allocator &other) BOOST_NOEXCEPT_OR_NOTHROW : Allocator(other.as_base()) {} //!Move constructor from related small_vector_allocator. //!Never throws template - BOOST_CONTAINER_FORCEINLINE small_vector_allocator(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator + (BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW : Allocator(::boost::move(other.as_base())) {} //!Assignment from other small_vector_allocator. //!Never throws - BOOST_CONTAINER_FORCEINLINE small_vector_allocator & operator=(BOOST_COPY_ASSIGN_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator & + operator=(BOOST_COPY_ASSIGN_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW { return static_cast(this->Allocator::operator=(other.as_base())); } //!Move constructor from other small_vector_allocator. //!Never throws - BOOST_CONTAINER_FORCEINLINE small_vector_allocator & operator=(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator & + operator=(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW { return static_cast(this->Allocator::operator=(::boost::move(other.as_base()))); } //!Assignment from related small_vector_allocator. //!Never throws template - BOOST_CONTAINER_FORCEINLINE small_vector_allocator & operator=(BOOST_COPY_ASSIGN_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator & + operator=(BOOST_COPY_ASSIGN_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW { return static_cast(this->Allocator::operator=(other.as_base())); } //!Move assignment from related small_vector_allocator. //!Never throws template - BOOST_CONTAINER_FORCEINLINE small_vector_allocator & operator=(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE small_vector_allocator & + operator=(BOOST_RV_REF(small_vector_allocator) other) BOOST_NOEXCEPT_OR_NOTHROW { return static_cast(this->Allocator::operator=(::boost::move(other.as_base()))); } //!Allocates storage from the standard-conforming allocator @@ -295,7 +303,7 @@ class small_vector_allocator //! //Clients can pass any small_vector. //! void read_any_small_vector_of_foo(const small_vector_base &in_parameter); //! -//! void modify_any_small_vector_of_foo(small_vector_base &out_parameter); +//! void modify_any_small_vector_of_foo(small_vector_base &in_out_parameter); //! //! void some_function() //! { @@ -499,46 +507,80 @@ class small_vector : public small_vector_base : base_type(initial_capacity_t(), internal_capacity()) {} - BOOST_CONTAINER_FORCEINLINE explicit small_vector(size_type n) - : base_type(initial_capacity_t(), internal_capacity()) - { this->resize(n); } - BOOST_CONTAINER_FORCEINLINE explicit small_vector(const allocator_type &a) : base_type(initial_capacity_t(), internal_capacity(), a) {} - small_vector(size_type n, const allocator_type &a) + BOOST_CONTAINER_FORCEINLINE explicit small_vector(size_type n) + : base_type(initial_capacity_t(), internal_capacity()) + { this->resize(n); } + + BOOST_CONTAINER_FORCEINLINE small_vector(size_type n, const allocator_type &a) : base_type(initial_capacity_t(), internal_capacity(), a) { this->resize(n); } - small_vector(const small_vector &other) + BOOST_CONTAINER_FORCEINLINE small_vector(size_type n, default_init_t) + : base_type(initial_capacity_t(), internal_capacity()) + { this->resize(n, default_init_t()); } + + BOOST_CONTAINER_FORCEINLINE small_vector(size_type n, default_init_t, const allocator_type &a) + : base_type(initial_capacity_t(), internal_capacity(), a) + { this->resize(n, default_init_t()); } + + BOOST_CONTAINER_FORCEINLINE small_vector(size_type n, const value_type &v) + : base_type(initial_capacity_t(), internal_capacity()) + { this->resize(n, v); } + + small_vector(size_type n, const value_type &v, const allocator_type &a) + : base_type(initial_capacity_t(), internal_capacity(), a) + { this->resize(n, v); } + + template + small_vector(InIt first, InIt last + BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_c + < container_detail::is_convertible::value + BOOST_MOVE_I container_detail::nat >::type * = 0) + ) + : base_type(initial_capacity_t(), internal_capacity()) + { this->assign(first, last); } + + template + BOOST_CONTAINER_FORCEINLINE small_vector(InIt first, InIt last, const allocator_type& a + BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I typename container_detail::disable_if_c + < container_detail::is_convertible::value + BOOST_MOVE_I container_detail::nat >::type * = 0) + ) + : base_type(initial_capacity_t(), internal_capacity(), a) + { this->assign(first, last); } + + BOOST_CONTAINER_FORCEINLINE small_vector(const small_vector &other) : base_type( initial_capacity_t(), internal_capacity() , allocator_traits_type::select_on_container_copy_construction(other.get_stored_allocator())) { this->assign(other.cbegin(), other.cend()); } - small_vector(const small_vector &other, const allocator_type &a) + BOOST_CONTAINER_FORCEINLINE small_vector(const small_vector &other, const allocator_type &a) : base_type(initial_capacity_t(), internal_capacity(), a) { this->assign(other.cbegin(), other.cend()); } - explicit small_vector(const base_type &other) + BOOST_CONTAINER_FORCEINLINE explicit small_vector(const base_type &other) : base_type( initial_capacity_t(), internal_capacity() , allocator_traits_type::select_on_container_copy_construction(other.get_stored_allocator())) { this->assign(other.cbegin(), other.cend()); } - explicit small_vector(BOOST_RV_REF(base_type) other) + BOOST_CONTAINER_FORCEINLINE explicit small_vector(BOOST_RV_REF(base_type) other) : base_type(initial_capacity_t(), internal_capacity(), ::boost::move(other.get_stored_allocator())) { this->move_construct_impl(other, other.get_stored_allocator()); } - small_vector(BOOST_RV_REF(small_vector) other) + BOOST_CONTAINER_FORCEINLINE small_vector(BOOST_RV_REF(small_vector) other) : base_type(initial_capacity_t(), internal_capacity(), ::boost::move(other.get_stored_allocator())) { this->move_construct_impl(other, other.get_stored_allocator()); } - small_vector(BOOST_RV_REF(small_vector) other, const allocator_type &a) + BOOST_CONTAINER_FORCEINLINE small_vector(BOOST_RV_REF(small_vector) other, const allocator_type &a) : base_type(initial_capacity_t(), internal_capacity(), a) { this->move_construct_impl(other, a); } #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - small_vector(std::initializer_list il, const allocator_type& a = allocator_type()) + BOOST_CONTAINER_FORCEINLINE small_vector(std::initializer_list il, const allocator_type& a = allocator_type()) : base_type(initial_capacity_t(), internal_capacity(), a) { this->assign(il.begin(), il.end()); diff --git a/test/vector_test.hpp b/test/vector_test.hpp index eee6374..659f140 100644 --- a/test/vector_test.hpp +++ b/test/vector_test.hpp @@ -95,10 +95,10 @@ bool vector_copyable_only(V1&, V2&, boost::container::container_detail::false_ty } //Function to check if both sets are equal -template -bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::container_detail::true_type) +template +bool vector_copyable_only(MyBoostVector &boostvector, MyStdVector &stdvector, boost::container::container_detail::true_type) { - typedef typename V1::value_type IntType; + typedef typename MyBoostVector::value_type IntType; std::size_t size = boostvector.size(); boostvector.insert(boostvector.end(), 50, IntType(1)); stdvector.insert(stdvector.end(), 50, 1); @@ -133,11 +133,13 @@ bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::cont if(!test::CheckEqualContainers(boostvector, stdvector)) return false; } { //Vector(const Vector &) - ::boost::movelib::unique_ptr const pv1 = ::boost::movelib::make_unique(boostvector); - ::boost::movelib::unique_ptr const pv2 = ::boost::movelib::make_unique(stdvector); + ::boost::movelib::unique_ptr const pv1 = + ::boost::movelib::make_unique(boostvector); + ::boost::movelib::unique_ptr const pv2 = + ::boost::movelib::make_unique(stdvector); - V1 &v1 = *pv1; - V2 &v2 = *pv2; + MyBoostVector &v1 = *pv1; + MyStdVector &v2 = *pv2; boostvector.clear(); stdvector.clear(); @@ -146,11 +148,13 @@ bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::cont if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } { //Vector(const Vector &, alloc) - ::boost::movelib::unique_ptr const pv1 = ::boost::movelib::make_unique(boostvector, typename V1::allocator_type()); - ::boost::movelib::unique_ptr const pv2 = ::boost::movelib::make_unique(stdvector); + ::boost::movelib::unique_ptr const pv1 = + ::boost::movelib::make_unique(boostvector, typename MyBoostVector::allocator_type()); + ::boost::movelib::unique_ptr const pv2 = + ::boost::movelib::make_unique(stdvector); - V1 &v1 = *pv1; - V2 &v2 = *pv2; + MyBoostVector &v1 = *pv1; + MyStdVector &v2 = *pv2; boostvector.clear(); stdvector.clear(); @@ -158,7 +162,47 @@ bool vector_copyable_only(V1 &boostvector, V2 &stdvector, boost::container::cont stdvector.assign(v2.begin(), v2.end()); if(!test::CheckEqualContainers(boostvector, stdvector)) return 1; } - + { //Vector(n, T) + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100, int(5)); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100, IntType(5)); + if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; + } + { //Vector(n, T, alloc) + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100, int(5)); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100, IntType(5), typename MyBoostVector::allocator_type()); + if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; + } + { //Vector(It, It) + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp2 = + ::boost::movelib::make_unique(boostvectorp->begin(), boostvectorp->end()); + if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; + } + { //Vector(It, It, alloc) + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp2 = + ::boost::movelib::make_unique(boostvectorp->begin(), boostvectorp->end(), typename MyBoostVector::allocator_type()); + if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; + } + { //resize(n, T) + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(); + stdvectorp->resize(100, int(9)); + boostvectorp->resize(100, IntType(9)); + if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; + } return true; } @@ -173,32 +217,45 @@ int vector_test() return 1; } { //Vector(n) - ::boost::movelib::unique_ptr const boostvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const stdvectorp = ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; } { //Vector(n, alloc) - ::boost::movelib::unique_ptr const boostvectorp = ::boost::movelib::make_unique(100, typename MyBoostVector::allocator_type()); - ::boost::movelib::unique_ptr const stdvectorp = ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100, typename MyBoostVector::allocator_type()); + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); if(!test::CheckEqualContainers(*boostvectorp, *stdvectorp)) return 1; } { //Vector(Vector &&) - ::boost::movelib::unique_ptr const stdvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp2 = ::boost::movelib::make_unique(::boost::move(*boostvectorp)); + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp2 = + ::boost::movelib::make_unique(::boost::move(*boostvectorp)); if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; } { //Vector(Vector &&, alloc) - ::boost::movelib::unique_ptr const stdvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp2 = ::boost::movelib::make_unique - (::boost::move(*boostvectorp), typename MyBoostVector::allocator_type()); + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp2 = + ::boost::movelib::make_unique + (::boost::move(*boostvectorp), typename MyBoostVector::allocator_type()); if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; } { //Vector operator=(Vector &&) - ::boost::movelib::unique_ptr const stdvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp = ::boost::movelib::make_unique(100); - ::boost::movelib::unique_ptr const boostvectorp2 = ::boost::movelib::make_unique(); + ::boost::movelib::unique_ptr const stdvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp = + ::boost::movelib::make_unique(100); + ::boost::movelib::unique_ptr const boostvectorp2 = + ::boost::movelib::make_unique(); *boostvectorp2 = ::boost::move(*boostvectorp); if(!test::CheckEqualContainers(*boostvectorp2, *stdvectorp)) return 1; }