1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
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>
19 namespace interprocess_container
{
20 namespace containers_detail
{
22 template <class SizeType
>
24 get_next_capacity(const SizeType max_size
25 ,const SizeType capacity
28 // if (n > max_size - capacity)
29 // throw std::length_error("get_next_capacity");
31 const SizeType m3
= max_size
/3;
34 return capacity
+ max_value(3*(capacity
+1)/5, n
);
37 return capacity
+ max_value((capacity
+1)/2, n
);
43 const T
&max_value(const T
&a
, const T
&b
)
44 { return a
> b
? a
: b
; }
47 const T
&min_value(const T
&a
, const T
&b
)
48 { return a
< b
? a
: b
; }
50 template<class SmartPtr
>
53 typedef typename
SmartPtr::value_type value_type
;
54 typedef value_type
*pointer
;
55 static pointer
get (const SmartPtr
&smartptr
)
56 { return smartptr
.get();}
60 struct smart_ptr_type
<T
*>
63 typedef value_type
*pointer
;
64 static pointer
get (pointer ptr
)
68 //!Overload for smart pointers to avoid ADL problems with get_pointer
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
76 inline void do_swap(T
& x
, T
& 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 {
93 #include <boost/interprocess/containers/container/detail/config_end.hpp>
95 #endif //#ifndef BOOST_CONTAINERS_DETAIL_UTILITIES_HPP