fix doc example typo
[boost.git] / boost / interprocess / containers / container / detail / utilities.hpp
blob5dad0dcad484a9c8f358f6758d82f7f17ef0e917
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2008. 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)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINERS_DETAIL_UTILITIES_HPP
12 #define BOOST_CONTAINERS_DETAIL_UTILITIES_HPP
14 #include <boost/interprocess/containers/container/detail/config_begin.hpp>
15 #include <cstdio>
16 #include <algorithm>
18 namespace boost {
19 namespace interprocess_container {
20 namespace containers_detail {
22 template <class SizeType>
23 SizeType
24 get_next_capacity(const SizeType max_size
25 ,const SizeType capacity
26 ,const SizeType n)
28 // if (n > max_size - capacity)
29 // throw std::length_error("get_next_capacity");
31 const SizeType m3 = max_size/3;
33 if (capacity < m3)
34 return capacity + max_value(3*(capacity+1)/5, n);
36 if (capacity < m3*2)
37 return capacity + max_value((capacity+1)/2, n);
39 return max_size;
42 template<class T>
43 const T &max_value(const T &a, const T &b)
44 { return a > b ? a : b; }
46 template<class T>
47 const T &min_value(const T &a, const T &b)
48 { return a < b ? a : b; }
50 template<class SmartPtr>
51 struct smart_ptr_type
53 typedef typename SmartPtr::value_type value_type;
54 typedef value_type *pointer;
55 static pointer get (const SmartPtr &smartptr)
56 { return smartptr.get();}
59 template<class T>
60 struct smart_ptr_type<T*>
62 typedef T value_type;
63 typedef value_type *pointer;
64 static pointer get (pointer ptr)
65 { return ptr;}
68 //!Overload for smart pointers to avoid ADL problems with get_pointer
69 template<class Ptr>
70 inline typename smart_ptr_type<Ptr>::pointer
71 get_pointer(const Ptr &ptr)
72 { return smart_ptr_type<Ptr>::get(ptr); }
74 //!To avoid ADL problems with swap
75 template <class T>
76 inline void do_swap(T& x, T& y)
78 using std::swap;
79 swap(x, y);
82 template <std::size_t OrigSize, std::size_t RoundTo>
83 struct ct_rounded_size
85 enum { value = ((OrigSize-1)/RoundTo+1)*RoundTo };
88 } //namespace containers_detail {
89 } //namespace interprocess_container {
90 } //namespace boost {
93 #include <boost/interprocess/containers/container/detail/config_end.hpp>
95 #endif //#ifndef BOOST_CONTAINERS_DETAIL_UTILITIES_HPP