PageRenderTime 45ms CodeModel.GetById 18ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/interprocess/containers/container/detail/utilities.hpp

http://hadesmem.googlecode.com/
C++ Header | 148 lines | 102 code | 28 blank | 18 comment | 6 complexity | 6b7bb117a6e99afc7d971446eb4399ea MD5 | raw file
  1//////////////////////////////////////////////////////////////////////////////
  2//
  3// (C) Copyright Ion Gaztanaga 2005-2009. 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//////////////////////////////////////////////////////////////////////////////
 10
 11#ifndef BOOST_CONTAINERS_DETAIL_UTILITIES_HPP
 12#define BOOST_CONTAINERS_DETAIL_UTILITIES_HPP
 13
 14#include "config_begin.hpp"
 15#include <cstdio>
 16#include <boost/type_traits/is_fundamental.hpp>
 17#include <boost/type_traits/is_pointer.hpp>
 18#include <boost/type_traits/is_enum.hpp>
 19#include <boost/type_traits/is_member_pointer.hpp>
 20#include INCLUDE_BOOST_CONTAINER_MOVE_HPP
 21#include INCLUDE_BOOST_CONTAINER_DETAIL_MPL_HPP
 22#include INCLUDE_BOOST_CONTAINER_DETAIL_TYPE_TRAITS_HPP
 23#include <algorithm>
 24
 25namespace boost {
 26namespace container {
 27namespace containers_detail {
 28
 29template<class T>
 30const T &max_value(const T &a, const T &b)
 31{  return a > b ? a : b;   }
 32
 33template<class T>
 34const T &min_value(const T &a, const T &b)
 35{  return a < b ? a : b;   }
 36
 37template <class SizeType>
 38SizeType
 39   get_next_capacity(const SizeType max_size
 40                    ,const SizeType capacity
 41                    ,const SizeType n)
 42{
 43//   if (n > max_size - capacity)
 44//      throw std::length_error("get_next_capacity");
 45
 46   const SizeType m3 = max_size/3;
 47
 48   if (capacity < m3)
 49      return capacity + max_value(3*(capacity+1)/5, n);
 50
 51   if (capacity < m3*2)
 52      return capacity + max_value((capacity+1)/2, n);
 53
 54   return max_size;
 55}
 56
 57template<class SmartPtr>
 58struct smart_ptr_type
 59{
 60   typedef typename SmartPtr::value_type value_type;
 61   typedef value_type *pointer;
 62   static pointer get (const SmartPtr &smartptr)
 63   {  return smartptr.get();}
 64};
 65
 66template<class T>
 67struct smart_ptr_type<T*>
 68{
 69   typedef T value_type;
 70   typedef value_type *pointer;
 71   static pointer get (pointer ptr)
 72   {  return ptr;}
 73};
 74
 75//!Overload for smart pointers to avoid ADL problems with get_pointer
 76template<class Ptr>
 77inline typename smart_ptr_type<Ptr>::pointer
 78get_pointer(const Ptr &ptr)
 79{  return smart_ptr_type<Ptr>::get(ptr);   }
 80
 81//!To avoid ADL problems with swap
 82template <class T>
 83inline void do_swap(T& x, T& y)
 84{
 85   using std::swap;
 86   swap(x, y);
 87}
 88
 89//Rounds "orig_size" by excess to round_to bytes
 90inline std::size_t get_rounded_size(std::size_t orig_size, std::size_t round_to)
 91{
 92   return ((orig_size-1)/round_to+1)*round_to;
 93}
 94
 95template <std::size_t OrigSize, std::size_t RoundTo>
 96struct ct_rounded_size
 97{
 98   enum { value = ((OrigSize-1)/RoundTo+1)*RoundTo };
 99};
100
101template <class _TypeT>
102struct __rw_is_enum
103{
104struct _C_no { };
105struct _C_yes { int _C_dummy [2]; };
106
107struct _C_indirect {
108// prevent classes with user-defined conversions from matching
109
110// use double to prevent float->int gcc conversion warnings
111_C_indirect (double);
112};
113
114// nested struct gets rid of bogus gcc errors
115struct _C_nest {
116// supply first argument to prevent HP aCC warnings
117static _C_no _C_is (int, ...);
118static _C_yes _C_is (int, _C_indirect);
119
120static _TypeT _C_make_T ();
121};
122
123enum {
124_C_val = sizeof (_C_yes)
125== sizeof (_C_nest::_C_is (0, _C_nest::_C_make_T ()))
126&& !::boost::is_fundamental<_TypeT>::value
127};
128
129}; 
130
131template<class T>
132struct move_const_ref_type
133   : if_c
134   < ::boost::is_fundamental<T>::value || ::boost::is_pointer<T>::value ||
135     ::boost::is_member_pointer<T>::value || ::boost::is_enum<T>::value
136   ,const T &
137   ,BOOST_MOVE_MACRO_CATCH_CONST_RLVALUE(T)
138   >
139{};
140
141}  //namespace containers_detail {
142}  //namespace container {
143}  //namespace boost {
144
145
146#include INCLUDE_BOOST_CONTAINER_DETAIL_CONFIG_END_HPP
147
148#endif   //#ifndef BOOST_CONTAINERS_DETAIL_UTILITIES_HPP