forked from boostorg/container
Added stored_size option to static_vector
This commit is contained in:
1 parent
c4cfad7402
commit
13603d7de1
6 files changed
+90
-17
No files matched your search
@@ -289,8 +289,8 @@ BOOST_INTRUSIVE_OPTION_TYPE(growth_factor, GrowthFactor, GrowthFactor, growth_fa
|
||||
//!
|
||||
//!If the maximum capacity() to be used is limited, a user can try to use 8-bit, 16-bit
|
||||
//!(e.g. in 32-bit machines), or 32-bit size types (e.g. in a 64 bit machine) to see if some
|
||||
//!memory can be saved for empty vectors. This could potentially performance benefits due to better
|
||||
//!cache usage.
|
||||
//!memory can be saved, specially for empty containers. This could potentially improve performance
|
||||
//!due to better cache usage.
|
||||
//!
|
||||
//!Note that alignment requirements can disallow theoretical space savings. Example:
|
||||
//!\c vector holds a pointer and two size types (for size and capacity), in a 32 bit machine
|
||||
@@ -301,7 +301,7 @@ BOOST_INTRUSIVE_OPTION_TYPE(growth_factor, GrowthFactor, GrowthFactor, growth_fa
|
||||
//!Measure the size of the resulting container and do not assume a smaller \c stored_size
|
||||
//!will always lead to a smaller sizeof(container).
|
||||
//!
|
||||
//!If a user tries to insert more elements than representable by \c stored_size, vector
|
||||
//!If a user tries to insert more elements than representable by \c stored_size, the container
|
||||
//!will throw a length_error.
|
||||
//!
|
||||
//!If this option is not specified, `allocator_traits<A>::size_type` (usually std::size_t) will
|
||||
@@ -337,7 +337,6 @@ struct vector_options
|
||||
|
||||
//! Helper alias metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::vector.
|
||||
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
|
||||
template<class ...Options>
|
||||
using vector_options_t = typename boost::container::vector_options<Options...>::type;
|
||||
|
||||
@@ -400,7 +399,6 @@ struct small_vector_options
|
||||
|
||||
//! Helper alias metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::small_vector.
|
||||
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
|
||||
template<class ...Options>
|
||||
using small_vector_options_t = typename boost::container::small_vector_options<Options...>::type;
|
||||
|
||||
@@ -427,20 +425,22 @@ BOOST_INTRUSIVE_OPTION_CONSTANT(throw_on_overflow, bool, ThrowOnOverflow, throw_
|
||||
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
template<bool ThrowOnOverflow, std::size_t InplaceAlignment>
|
||||
template<bool ThrowOnOverflow, std::size_t InplaceAlignment, class StoredSizeType>
|
||||
struct static_vector_opt
|
||||
{
|
||||
BOOST_STATIC_CONSTEXPR bool throw_on_overflow = ThrowOnOverflow;
|
||||
BOOST_STATIC_CONSTEXPR std::size_t inplace_alignment = InplaceAlignment;
|
||||
typedef StoredSizeType stored_size_type;
|
||||
};
|
||||
|
||||
typedef static_vector_opt<true, 0u> static_vector_null_opt;
|
||||
typedef static_vector_opt<true, 0u, void> static_vector_null_opt;
|
||||
|
||||
#endif //!defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
//! Helper metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::static_vector.
|
||||
//! Supported options are: \c boost::container::throw_on_overflow and \c boost::container::inplace_alignment
|
||||
//! Supported options are: \c boost::container::throw_on_overflow, \c boost::container::inplace_alignment
|
||||
//! and \c boost::container::stored_size.
|
||||
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) || defined(BOOST_CONTAINER_VARIADIC_TEMPLATES)
|
||||
template<class ...Options>
|
||||
#else
|
||||
@@ -458,7 +458,9 @@ struct static_vector_options
|
||||
#endif
|
||||
>::type packed_options;
|
||||
typedef static_vector_opt< packed_options::throw_on_overflow
|
||||
, packed_options::inplace_alignment> implementation_defined;
|
||||
, packed_options::inplace_alignment
|
||||
, typename packed_options::stored_size_type
|
||||
> implementation_defined;
|
||||
/// @endcond
|
||||
typedef implementation_defined type;
|
||||
};
|
||||
@@ -467,7 +469,6 @@ struct static_vector_options
|
||||
|
||||
//! Helper alias metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::static_vector.
|
||||
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
|
||||
template<class ...Options>
|
||||
using static_vector_options_t = typename boost::container::static_vector_options<Options...>::type;
|
||||
|
||||
@@ -587,7 +588,6 @@ struct devector_options
|
||||
|
||||
//! Helper alias metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::devector.
|
||||
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
|
||||
template<class ...Options>
|
||||
using devector_options_t = typename boost::container::devector_options<Options...>::type;
|
||||
|
||||
@@ -643,7 +643,6 @@ struct deque_options
|
||||
|
||||
//! Helper alias metafunction to combine options into a single type to be used
|
||||
//! by \c boost::container::deque.
|
||||
//! Supported options are: \c boost::container::block_bytes
|
||||
template<class ...Options>
|
||||
using deque_options_t = typename boost::container::deque_options<Options...>::type;
|
||||
|
||||
|
||||
@@ -102,6 +102,19 @@ struct get_static_vector_opt<void>
|
||||
typedef static_vector_null_opt type;
|
||||
};
|
||||
|
||||
template<class Options>
|
||||
struct get_vector_opt_from_static_vector_opt
|
||||
{
|
||||
typedef typename get_static_vector_opt<Options>::type options_t;
|
||||
typedef vector_opt<void, typename options_t::stored_size_type> type;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct get_vector_opt_from_static_vector_opt<void>
|
||||
{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
template <typename T, std::size_t Capacity, class Options>
|
||||
struct get_static_vector_allocator
|
||||
{
|
||||
@@ -114,7 +127,6 @@ struct get_static_vector_allocator
|
||||
> type;
|
||||
};
|
||||
|
||||
|
||||
} //namespace dtl {
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
@@ -148,12 +160,18 @@ struct get_static_vector_allocator
|
||||
//! is specified, by default throw_on_overflow<true> option is set.
|
||||
template <typename T, std::size_t Capacity, class Options BOOST_CONTAINER_DOCONLY(= void) >
|
||||
class static_vector
|
||||
: public vector<T, typename dtl::get_static_vector_allocator< T, Capacity, Options>::type>
|
||||
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
: public vector< T
|
||||
, typename dtl::get_static_vector_allocator< T, Capacity, Options>::type
|
||||
, typename dtl::get_vector_opt_from_static_vector_opt<Options>::type
|
||||
>
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
typedef typename dtl::get_static_vector_allocator< T, Capacity, Options>::type allocator_type;
|
||||
typedef vector<T, allocator_type > base_t;
|
||||
typedef typename dtl::get_vector_opt_from_static_vector_opt<Options>::type options_type;
|
||||
typedef vector<T, allocator_type, options_type> base_t;
|
||||
|
||||
BOOST_COPYABLE_AND_MOVABLE(static_vector)
|
||||
|
||||
|
||||
@@ -643,7 +643,7 @@ struct vector_alloc_holder<Allocator, StoredSizeType, version_0>
|
||||
template<class AllocConvertible>
|
||||
vector_alloc_holder(vector_uninitialized_size_t, BOOST_FWD_REF(AllocConvertible) a, size_type initial_size)
|
||||
: allocator_type(boost::forward<AllocConvertible>(a))
|
||||
, m_size(initial_size) //Size is initialized here...
|
||||
, m_size(static_cast<stored_size_type>(initial_size)) //Size is initialized here...
|
||||
{
|
||||
//... and capacity here, so vector, must call uninitialized_xxx in the derived constructor
|
||||
this->priv_first_allocation(initial_size);
|
||||
@@ -652,7 +652,7 @@ struct vector_alloc_holder<Allocator, StoredSizeType, version_0>
|
||||
//Constructor, does not throw
|
||||
vector_alloc_holder(vector_uninitialized_size_t, size_type initial_size)
|
||||
: allocator_type()
|
||||
, m_size(initial_size) //Size is initialized here...
|
||||
, m_size(static_cast<stored_size_type>(initial_size)) //Size is initialized here...
|
||||
{
|
||||
//... and capacity here, so vector, must call uninitialized_xxx in the derived constructor
|
||||
this->priv_first_allocation(initial_size);
|
||||
|
||||
Reference in new issue
Block a user