1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
11 #define BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/throw_exception.hpp>
24 #include <boost/container/detail/min_max.hpp>
26 #include <boost/static_assert.hpp>
32 template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
33 struct grow_factor_ratio
35 BOOST_STATIC_ASSERT(Numerator > Denominator);
36 BOOST_STATIC_ASSERT(Numerator < 100);
37 BOOST_STATIC_ASSERT(Denominator < 100);
38 BOOST_STATIC_ASSERT(Denominator == 1 || (0 != Numerator % Denominator));
40 template<class SizeType>
41 SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
43 const SizeType overflow_limit = ((SizeType)-1) / Numerator;
47 if(cur_cap <= overflow_limit){
48 new_cap = cur_cap * Numerator / Denominator;
50 else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
51 new_cap = (SizeType)-1;
56 return max_value(SizeType(Minimum), max_value(cur_cap+add_min_cap, min_value(max_cap, new_cap)));
62 struct growth_factor_50
63 : dtl::grow_factor_ratio<0, 3, 2>
66 struct growth_factor_60
67 : dtl::grow_factor_ratio<0, 8, 5>
70 struct growth_factor_100
71 : dtl::grow_factor_ratio<0, 2, 1>
74 } //namespace container {
77 #endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP