Chris@102: ////////////////////////////////////////////////////////////////////////////// Chris@102: // Chris@102: // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost Chris@102: // Software License, Version 1.0. (See accompanying file Chris@102: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@102: // Chris@102: // See http://www.boost.org/libs/container for documentation. Chris@102: // Chris@102: ////////////////////////////////////////////////////////////////////////////// Chris@102: #ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP Chris@102: #define BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP Chris@102: Chris@102: #ifndef BOOST_CONFIG_HPP Chris@102: # include Chris@102: #endif Chris@102: Chris@102: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@102: # pragma once Chris@102: #endif Chris@102: Chris@102: // container Chris@102: #include Chris@102: // container/detail Chris@102: #include Chris@102: Chris@102: namespace boost { Chris@102: namespace container { Chris@102: namespace container_detail { Chris@102: Chris@102: enum NextCapacityOption { NextCapacityDouble, NextCapacity60Percent }; Chris@102: Chris@102: template Chris@102: struct next_capacity_calculator; Chris@102: Chris@102: template Chris@102: struct next_capacity_calculator Chris@102: { Chris@102: static SizeType get(const SizeType max_size Chris@102: ,const SizeType capacity Chris@102: ,const SizeType n) Chris@102: { Chris@102: const SizeType remaining = max_size - capacity; Chris@102: if ( remaining < n ) Chris@102: boost::container::throw_length_error("get_next_capacity, allocator's max_size reached"); Chris@102: const SizeType additional = max_value(n, capacity); Chris@102: return ( remaining < additional ) ? max_size : ( capacity + additional ); Chris@102: } Chris@102: }; Chris@102: Chris@102: template Chris@102: struct next_capacity_calculator Chris@102: { Chris@102: static SizeType get(const SizeType max_size Chris@102: ,const SizeType capacity Chris@102: ,const SizeType n) Chris@102: { Chris@102: const SizeType remaining = max_size - capacity; Chris@102: if ( remaining < n ) Chris@102: boost::container::throw_length_error("get_next_capacity, allocator's max_size reached"); Chris@102: const SizeType m3 = max_size/3; Chris@102: Chris@102: if (capacity < m3) Chris@102: return capacity + max_value(3*(capacity+1)/5, n); Chris@102: Chris@102: if (capacity < m3*2) Chris@102: return capacity + max_value((capacity+1)/2, n); Chris@102: return max_size; Chris@102: } Chris@102: }; Chris@102: Chris@102: } //namespace container_detail { Chris@102: } //namespace container { Chris@102: } //namespace boost { Chris@102: Chris@102: #endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP