diff --git a/doc/container.qbk b/doc/container.qbk index daec5ce..2c3dd4e 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -666,7 +666,9 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7921 #7921], [@https://svn.boost.org/trac/boost/ticket/7969 #7969], [@https://svn.boost.org/trac/boost/ticket/8118 #8118], - [@https://svn.boost.org/trac/boost/ticket/8294 #8294]. + [@https://svn.boost.org/trac/boost/ticket/8294 #8294], + [@https://svn.boost.org/trac/boost/ticket/8553 #8553]. +* Added experimental `static_vector` class. [endsect] diff --git a/include/boost/container/scoped_allocator.hpp b/include/boost/container/scoped_allocator.hpp index 022c73e..f9f2108 100644 --- a/include/boost/container/scoped_allocator.hpp +++ b/include/boost/container/scoped_allocator.hpp @@ -664,6 +664,12 @@ class scoped_allocator_adaptor_base return *this; } + void swap(scoped_allocator_adaptor_base &r) + { + boost::container::swap_dispatch(this->outer_allocator(), r.outer_allocator()); + boost::container::swap_dispatch(this->m_inner, r.inner_allocator()); + } + inner_allocator_type& inner_allocator() { return m_inner; } @@ -812,6 +818,12 @@ class scoped_allocator_adaptor_baseouter_allocator(), r.outer_allocator()); \ + boost::container::swap_dispatch(this->m_inner, r.inner_allocator()); \ + } \ + \ inner_allocator_type& inner_allocator() \ { return m_inner; } \ \ @@ -931,6 +943,11 @@ class scoped_allocator_adaptor_base return *this; } + void swap(scoped_allocator_adaptor_base &r) + { + boost::container::swap_dispatch(this->outer_allocator(), r.outer_allocator()); + } + inner_allocator_type& inner_allocator() { return static_cast(*this); } @@ -1158,6 +1175,18 @@ class scoped_allocator_adaptor return *this; } + //! Effects: swaps *this with r. + //! + void swap(scoped_allocator_adaptor &r) + { + base_type::swap(r); + } + + //! Effects: swaps *this with r. + //! + friend void swap(scoped_allocator_adaptor &l, scoped_allocator_adaptor &r) + { l.swap(r); } + //! Returns: //! `static_cast(*this)`. outer_allocator_type & outer_allocator() diff --git a/include/boost/container/static_vector.hpp b/include/boost/container/static_vector.hpp index 020a208..fb97b7f 100644 --- a/include/boost/container/static_vector.hpp +++ b/include/boost/container/static_vector.hpp @@ -21,34 +21,6 @@ namespace boost { namespace container { -/** - * @defgroup static_vector_non_member static_vector non-member functions - */ - -/** - * @brief A variable-size array container with fixed capacity. - * - * static_vector is a sequence container like boost::container::vector with contiguous storage that can - * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array. - * - * A static_vector is a sequence that supports random access to elements, constant time insertion and - * removal of elements at the end, and linear time insertion and removal of elements at the beginning or - * in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity - * because elements are stored within the object itself similarly to an array. However, objects are - * initialized as they are inserted into static_vector unlike C arrays or std::array which must construct - * all elements on instantiation. The behavior of static_vector enables the use of statically allocated - * elements in cases with complex object lifetime requirements that would otherwise not be trivially - * possible. - * - * @par Error Handling - * Insertion beyond the capacity and out of bounds errors results in calling throw_bad_alloc(). - * The reason for this is because unlike vectors, static_vector does not perform allocation. - * - * @tparam Value The type of element that will be stored. - * @tparam Capacity The maximum number of elements static_vector can store, fixed at compile time. - */ - - namespace container_detail { template @@ -89,7 +61,32 @@ class static_storage_allocator } //namespace container_detail { +/** + * @defgroup static_vector_non_member static_vector non-member functions + */ +/** + * @brief A variable-size array container with fixed capacity. + * + * static_vector is a sequence container like boost::container::vector with contiguous storage that can + * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array. + * + * A static_vector is a sequence that supports random access to elements, constant time insertion and + * removal of elements at the end, and linear time insertion and removal of elements at the beginning or + * in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity + * because elements are stored within the object itself similarly to an array. However, objects are + * initialized as they are inserted into static_vector unlike C arrays or std::array which must construct + * all elements on instantiation. The behavior of static_vector enables the use of statically allocated + * elements in cases with complex object lifetime requirements that would otherwise not be trivially + * possible. + * + * @par Error Handling + * Insertion beyond the capacity and out of bounds errors results in calling throw_bad_alloc(). + * The reason for this is because unlike vectors, static_vector does not perform allocation. + * + * @tparam Value The type of element that will be stored. + * @tparam Capacity The maximum number of elements static_vector can store, fixed at compile time. + */ template class static_vector : public vector > diff --git a/test/scoped_allocator_adaptor_test.cpp b/test/scoped_allocator_adaptor_test.cpp index 1855127..61e8c7b 100644 --- a/test/scoped_allocator_adaptor_test.cpp +++ b/test/scoped_allocator_adaptor_test.cpp @@ -9,6 +9,7 @@ ////////////////////////////////////////////////////////////////////////////// #include #include +#include #include #include #include @@ -461,6 +462,19 @@ int main() BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_swap::value )); } + //Default constructor + { + Scoped0Inner s0i; + Scoped1Inner s1i; + //Swap + { + Scoped0Inner s0i2; + Scoped1Inner s1i2; + boost::container::swap_dispatch(s0i, s0i2); + boost::container::swap_dispatch(s1i, s1i2); + } + } + //Default constructor { Scoped0Inner s0i;