Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:12

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
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 // container
0025 #include <boost/container/throw_exception.hpp>
0026 // container/detail
0027 #include <boost/container/detail/min_max.hpp>
0028 
0029 #include <boost/static_assert.hpp>
0030 
0031 namespace boost {
0032 namespace container {
0033 namespace dtl {
0034 
0035 template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
0036 struct grow_factor_ratio
0037 {
0038    BOOST_STATIC_ASSERT(Numerator > Denominator);
0039    BOOST_STATIC_ASSERT(Numerator   < 100);
0040    BOOST_STATIC_ASSERT(Denominator < 100);
0041    BOOST_STATIC_ASSERT(Denominator == 1 || (0 != Numerator % Denominator));
0042 
0043    template<class SizeType>
0044    SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
0045    {
0046       const SizeType overflow_limit  = ((SizeType)-1) / Numerator;
0047 
0048       SizeType new_cap = 0;
0049 
0050       if(cur_cap <= overflow_limit){
0051          new_cap = SizeType(cur_cap * Numerator / Denominator);
0052       }
0053       else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
0054          new_cap = (SizeType)-1;
0055       }
0056       else{
0057          new_cap = SizeType(new_cap*Numerator);
0058       }
0059       return max_value<SizeType>
0060                ( SizeType(Minimum)
0061                , max_value<SizeType>
0062                   ( SizeType(cur_cap+add_min_cap)
0063                   , min_value<SizeType>(max_cap, new_cap))
0064                );
0065    }
0066 };
0067 
0068 }  //namespace dtl {
0069 
0070 struct growth_factor_50
0071    : dtl::grow_factor_ratio<0, 3, 2>
0072 {};
0073 
0074 struct growth_factor_60
0075    : dtl::grow_factor_ratio<0, 8, 5>
0076 {};
0077 
0078 struct growth_factor_100
0079    : dtl::grow_factor_ratio<0, 2, 1>
0080 {};
0081 
0082 template<class SizeType>
0083 BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &, SizeType)
0084 {}
0085 
0086 template<class SizeType, class SomeStoredSizeType>
0087 BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &s, SomeStoredSizeType)
0088 {
0089    if (s >= SomeStoredSizeType(-1) ) 
0090       s = SomeStoredSizeType(-1);
0091 }
0092 
0093 }  //namespace container {
0094 }  //namespace boost {
0095 
0096 #include <boost/container/detail/config_end.hpp>
0097 
0098 #endif   //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP