[SVN r84360]
This commit is contained in:
Ion Gaztañaga
2013-05-18 21:06:19 +00:00
parent 53c232e485
commit dd1cc03280
4 changed files with 71 additions and 29 deletions

View File

@@ -666,7 +666,9 @@ use [*Boost.Container]? There are several reasons for that:
* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7921 #7921], * 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/7969 #7969],
[@https://svn.boost.org/trac/boost/ticket/8118 #8118], [@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] [endsect]

View File

@@ -664,6 +664,12 @@ class scoped_allocator_adaptor_base
return *this; 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() inner_allocator_type& inner_allocator()
{ return m_inner; } { return m_inner; }
@@ -812,6 +818,12 @@ class scoped_allocator_adaptor_base<OuterAlloc, true
return *this; \ 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() \ inner_allocator_type& inner_allocator() \
{ return m_inner; } \ { return m_inner; } \
\ \
@@ -931,6 +943,11 @@ class scoped_allocator_adaptor_base
return *this; return *this;
} }
void swap(scoped_allocator_adaptor_base &r)
{
boost::container::swap_dispatch(this->outer_allocator(), r.outer_allocator());
}
inner_allocator_type& inner_allocator() inner_allocator_type& inner_allocator()
{ return static_cast<inner_allocator_type&>(*this); } { return static_cast<inner_allocator_type&>(*this); }
@@ -1158,6 +1175,18 @@ class scoped_allocator_adaptor
return *this; return *this;
} }
//! <b>Effects</b>: swaps *this with r.
//!
void swap(scoped_allocator_adaptor &r)
{
base_type::swap(r);
}
//! <b>Effects</b>: swaps *this with r.
//!
friend void swap(scoped_allocator_adaptor &l, scoped_allocator_adaptor &r)
{ l.swap(r); }
//! <b>Returns</b>: //! <b>Returns</b>:
//! `static_cast<OuterAlloc&>(*this)`. //! `static_cast<OuterAlloc&>(*this)`.
outer_allocator_type & outer_allocator() outer_allocator_type & outer_allocator()

View File

@@ -21,34 +21,6 @@
namespace boost { namespace container { 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 { namespace container_detail {
template<class T, std::size_t N> template<class T, std::size_t N>
@@ -89,7 +61,32 @@ class static_storage_allocator
} //namespace container_detail { } //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 <typename Value, std::size_t Capacity> template <typename Value, std::size_t Capacity>
class static_vector class static_vector
: public vector<Value, container_detail::static_storage_allocator<Value, Capacity> > : public vector<Value, container_detail::static_storage_allocator<Value, Capacity> >

View File

@@ -9,6 +9,7 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/config_begin.hpp> #include <boost/container/detail/config_begin.hpp>
#include <boost/container/scoped_allocator_fwd.hpp> #include <boost/container/scoped_allocator_fwd.hpp>
#include <boost/container/detail/utilities.hpp>
#include <cstddef> #include <cstddef>
#include <boost/container/detail/mpl.hpp> #include <boost/container/detail/mpl.hpp>
#include <boost/move/utility.hpp> #include <boost/move/utility.hpp>
@@ -461,6 +462,19 @@ int main()
BOOST_STATIC_ASSERT(( Scoped2InnerTTT::propagate_on_container_swap::value )); 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 //Default constructor
{ {
Scoped0Inner s0i; Scoped0Inner s0i;