Skip to content

Commit d4e3817

Browse files
committed
Add options "stored_size" and "growth_factor" options to string. Make string's default growth factor the same as vector's (60%)
1 parent 6689e38 commit d4e3817

File tree

6 files changed

+407
-163
lines changed

6 files changed

+407
-163
lines changed

include/boost/container/container_fwd.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ struct small_flat_multimap_of
272272
};
273273

274274
template <class CharT
275-
,class Traits = std::char_traits<CharT>
276-
,class Allocator = void >
275+
,class Traits = std::char_traits<CharT>
276+
,class Allocator = void
277+
,class Options = void >
277278
class basic_string;
278279

279280
typedef basic_string <char> string;

include/boost/container/detail/next_capacity.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,18 @@ inline void clamp_by_stored_size_type(SizeType &, SizeType)
8484
template<class SizeType, class SomeStoredSizeType>
8585
inline void clamp_by_stored_size_type(SizeType &s, SomeStoredSizeType)
8686
{
87-
if (s >= SomeStoredSizeType(-1) )
87+
if (s > SomeStoredSizeType(-1) )
8888
s = SomeStoredSizeType(-1);
8989
}
9090

91+
template<class SizeType, class SomeStoredSizeType>
92+
inline void clamp_by_half_stored_size_type(SizeType &s, SomeStoredSizeType)
93+
{
94+
const SizeType half_max = SizeType(SomeStoredSizeType(-1)) >> 1u;
95+
if (s > half_max )
96+
s = half_max;
97+
}
98+
9199
} //namespace container {
92100
} //namespace boost {
93101

include/boost/container/options.hpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ class default_next_capacity;
244244

245245
typedef vector_opt<void, void> vector_null_opt;
246246

247+
template<class GrowthType, class StoredSizeType>
248+
struct string_opt
249+
{
250+
typedef GrowthType growth_factor_type;
251+
typedef StoredSizeType stored_size_type;
252+
253+
template<class AllocTraits>
254+
struct get_stored_size_type
255+
: get_stored_size_type_with_alloctraits<AllocTraits, StoredSizeType>
256+
{};
257+
};
258+
259+
typedef string_opt<void, void> string_null_opt;
260+
261+
struct growth_factor_50;
262+
263+
struct growth_factor_60;
264+
265+
struct growth_factor_100;
266+
247267
#else
248268

249269
//!This growth factor argument specifies that the container should increase its
@@ -674,6 +694,40 @@ using deque_options_t = typename boost::container::deque_options<Options...>::ty
674694

675695
#endif
676696

697+
//! Helper metafunction to combine options into a single type to be used
698+
//! by \c boost::container::string.
699+
//! Supported options are: \c boost::container::growth_factor and \c boost::container::stored_size
700+
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED) || defined(BOOST_CONTAINER_VARIADIC_TEMPLATES)
701+
template<class ...Options>
702+
#else
703+
template<class O1 = void, class O2 = void, class O3 = void, class O4 = void>
704+
#endif
705+
struct string_options
706+
{
707+
/// @cond
708+
typedef typename ::boost::intrusive::pack_options
709+
< string_null_opt,
710+
#if !defined(BOOST_CONTAINER_VARIADIC_TEMPLATES)
711+
O1, O2, O3, O4
712+
#else
713+
Options...
714+
#endif
715+
>::type packed_options;
716+
typedef string_opt< typename packed_options::growth_factor_type
717+
, typename packed_options::stored_size_type> implementation_defined;
718+
/// @endcond
719+
typedef implementation_defined type;
720+
};
721+
722+
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
723+
724+
//! Helper alias metafunction to combine options into a single type to be used
725+
//! by \c boost::container::string.
726+
template<class ...Options>
727+
using string_options_t = typename boost::container::string_options<Options...>::type;
728+
729+
#endif
730+
677731
//!This option specifies the maximum size of a block in bytes: this delimites the number of contiguous elements
678732
//!that will be allocated by some containers as min(1u, BlockBytes/sizeof(value_type))
679733
//!A value zero represents the default value.

0 commit comments

Comments
 (0)