File indexing completed on 2025-07-05 08:28:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
0011 #define BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
0012
0013 #ifndef BOOST_CONFIG_HPP
0014 # include <boost/config.hpp>
0015 #endif
0016
0017 #if defined(BOOST_HAS_PRAGMA_ONCE)
0018 # pragma once
0019 #endif
0020
0021 #include <boost/container/detail/config_begin.hpp>
0022 #include <boost/container/detail/workaround.hpp>
0023
0024
0025 #include <boost/container/throw_exception.hpp>
0026
0027 #include <boost/container/detail/min_max.hpp>
0028
0029 namespace boost {
0030 namespace container {
0031 namespace dtl {
0032
0033 template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
0034 struct grow_factor_ratio
0035 {
0036 BOOST_CONTAINER_STATIC_ASSERT(Numerator > Denominator);
0037 BOOST_CONTAINER_STATIC_ASSERT(Numerator < 100);
0038 BOOST_CONTAINER_STATIC_ASSERT(Denominator < 100);
0039 BOOST_CONTAINER_STATIC_ASSERT(Denominator == 1 || (0 != Numerator % Denominator));
0040
0041 template<class SizeType>
0042 SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
0043 {
0044 const SizeType overflow_limit = ((SizeType)-1) / Numerator;
0045
0046 SizeType new_cap = 0;
0047
0048 if(cur_cap <= overflow_limit){
0049 new_cap = SizeType(cur_cap * Numerator / Denominator);
0050 }
0051 else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
0052 new_cap = (SizeType)-1;
0053 }
0054 else{
0055 new_cap = SizeType(new_cap*Numerator);
0056 }
0057 return max_value<SizeType>
0058 ( SizeType(Minimum)
0059 , max_value<SizeType>
0060 ( SizeType(cur_cap+add_min_cap)
0061 , min_value<SizeType>(max_cap, new_cap))
0062 );
0063 }
0064 };
0065
0066 }
0067
0068 struct growth_factor_50
0069 : dtl::grow_factor_ratio<0, 3, 2>
0070 {};
0071
0072 struct growth_factor_60
0073 : dtl::grow_factor_ratio<0, 8, 5>
0074 {};
0075
0076 struct growth_factor_100
0077 : dtl::grow_factor_ratio<0, 2, 1>
0078 {};
0079
0080 template<class SizeType>
0081 inline void clamp_by_stored_size_type(SizeType &, SizeType)
0082 {}
0083
0084 template<class SizeType, class SomeStoredSizeType>
0085 inline void clamp_by_stored_size_type(SizeType &s, SomeStoredSizeType)
0086 {
0087 if (s >= SomeStoredSizeType(-1) )
0088 s = SomeStoredSizeType(-1);
0089 }
0090
0091 }
0092 }
0093
0094 #include <boost/container/detail/config_end.hpp>
0095
0096 #endif