epoc32/include/stdapis/boost/detail/allocator_utilities.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/detail/allocator_utilities.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,185 @@
     1.4 +/* Copyright 2003-2005 Joaquín M López Muñoz.
     1.5 + * Distributed under the Boost Software License, Version 1.0.
     1.6 + * (See accompanying file LICENSE_1_0.txt or copy at
     1.7 + * http://www.boost.org/LICENSE_1_0.txt)
     1.8 + *
     1.9 + * See Boost website at http://www.boost.org/
    1.10 + */
    1.11 +
    1.12 +#ifndef BOOST_DETAIL_ALLOCATOR_UTILITIES_HPP
    1.13 +#define BOOST_DETAIL_ALLOCATOR_UTILITIES_HPP
    1.14 +
    1.15 +#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
    1.16 +#include <boost/detail/workaround.hpp>
    1.17 +#include <boost/mpl/aux_/msvc_never_true.hpp>
    1.18 +#include <boost/mpl/eval_if.hpp>
    1.19 +#include <boost/type_traits/is_same.hpp>
    1.20 +#include <cstddef>
    1.21 +#include <memory>
    1.22 +#include <new>
    1.23 +
    1.24 +namespace boost{
    1.25 +
    1.26 +namespace detail{
    1.27 +
    1.28 +/* Allocator adaption layer. Some stdlibs provide allocators without rebind
    1.29 + * and template ctors. These facilities are simulated with the external
    1.30 + * template class rebind_to and the aid of partial_std_allocator_wrapper.
    1.31 + */
    1.32 +
    1.33 +namespace allocator{
    1.34 +
    1.35 +/* partial_std_allocator_wrapper inherits the functionality of a std
    1.36 + * allocator while providing a templatized ctor.
    1.37 + */
    1.38 +
    1.39 +template<typename Type>
    1.40 +class partial_std_allocator_wrapper:public std::allocator<Type>
    1.41 +{
    1.42 +public:
    1.43 +  partial_std_allocator_wrapper(){};
    1.44 +
    1.45 +  template<typename Other>
    1.46 +  partial_std_allocator_wrapper(const partial_std_allocator_wrapper<Other>&){}
    1.47 +
    1.48 +  partial_std_allocator_wrapper(const std::allocator<Type>& x):
    1.49 +    std::allocator<Type>(x)
    1.50 +  {
    1.51 +  };
    1.52 +
    1.53 +#if defined(BOOST_DINKUMWARE_STDLIB)
    1.54 +  /* Dinkumware guys didn't provide a means to call allocate() without
    1.55 +   * supplying a hint, in disagreement with the standard.
    1.56 +   */
    1.57 +
    1.58 +  Type* allocate(std::size_t n,const void* hint=0)
    1.59 +  {
    1.60 +    std::allocator<Type>& a=*this;
    1.61 +    return a.allocate(n,hint);
    1.62 +  }
    1.63 +#endif
    1.64 +
    1.65 +};
    1.66 +
    1.67 +/* Detects whether a given allocator belongs to a defective stdlib not
    1.68 + * having the required member templates.
    1.69 + * Note that it does not suffice to check the Boost.Config stdlib
    1.70 + * macros, as the user might have passed a custom, compliant allocator.
    1.71 + * The checks also considers partial_std_allocator_wrapper to be
    1.72 + * a standard defective allocator.
    1.73 + */
    1.74 +
    1.75 +#if defined(BOOST_NO_STD_ALLOCATOR)&&\
    1.76 +  (defined(BOOST_HAS_PARTIAL_STD_ALLOCATOR)||defined(BOOST_DINKUMWARE_STDLIB))
    1.77 +
    1.78 +template<typename Allocator>
    1.79 +struct is_partial_std_allocator
    1.80 +{
    1.81 +  BOOST_STATIC_CONSTANT(bool,
    1.82 +    value=
    1.83 +      (is_same<
    1.84 +        std::allocator<BOOST_DEDUCED_TYPENAME Allocator::value_type>,
    1.85 +        Allocator
    1.86 +      >::value)||
    1.87 +      (is_same<
    1.88 +        partial_std_allocator_wrapper<
    1.89 +          BOOST_DEDUCED_TYPENAME Allocator::value_type>,
    1.90 +        Allocator
    1.91 +      >::value));
    1.92 +};
    1.93 +
    1.94 +#else
    1.95 +
    1.96 +template<typename Allocator>
    1.97 +struct is_partial_std_allocator
    1.98 +{
    1.99 +  BOOST_STATIC_CONSTANT(bool,value=false);
   1.100 +};
   1.101 +
   1.102 +#endif
   1.103 +
   1.104 +/* rebind operations for defective std allocators */
   1.105 +
   1.106 +template<typename Allocator,typename Type>
   1.107 +struct partial_std_allocator_rebind_to
   1.108 +{
   1.109 +  typedef partial_std_allocator_wrapper<Type> type;
   1.110 +};
   1.111 +
   1.112 +/* rebind operation in all other cases */
   1.113 +
   1.114 +#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
   1.115 +/* Workaround for a problem in MSVC with dependent template typedefs
   1.116 + * when doing rebinding of allocators.
   1.117 + * Modeled after <boost/mpl/aux_/msvc_dtw.hpp> (thanks, Aleksey!)
   1.118 + */
   1.119 +
   1.120 +template<typename Allocator>
   1.121 +struct rebinder
   1.122 +{
   1.123 +  template<bool> struct fake_allocator:Allocator{};
   1.124 +  template<> struct fake_allocator<true>
   1.125 +  {
   1.126 +    template<typename Type> struct rebind{};
   1.127 +  };
   1.128 +
   1.129 +  template<typename Type>
   1.130 +  struct result:
   1.131 +    fake_allocator<mpl::aux::msvc_never_true<Allocator>::value>::
   1.132 +      template rebind<Type>
   1.133 +  {
   1.134 +  };
   1.135 +};
   1.136 +#else
   1.137 +template<typename Allocator>
   1.138 +struct rebinder
   1.139 +{
   1.140 +  template<typename Type>
   1.141 +  struct result
   1.142 +  {
   1.143 +      typedef typename Allocator::BOOST_NESTED_TEMPLATE 
   1.144 +          rebind<Type>::other other;
   1.145 +  };
   1.146 +};
   1.147 +#endif
   1.148 +
   1.149 +template<typename Allocator,typename Type>
   1.150 +struct compliant_allocator_rebind_to
   1.151 +{
   1.152 +  typedef typename rebinder<Allocator>::
   1.153 +      BOOST_NESTED_TEMPLATE result<Type>::other type;
   1.154 +};
   1.155 +
   1.156 +/* rebind front-end */
   1.157 +
   1.158 +template<typename Allocator,typename Type>
   1.159 +struct rebind_to:
   1.160 +  mpl::eval_if_c<
   1.161 +    is_partial_std_allocator<Allocator>::value,
   1.162 +    partial_std_allocator_rebind_to<Allocator,Type>,
   1.163 +    compliant_allocator_rebind_to<Allocator,Type>
   1.164 +  >
   1.165 +{
   1.166 +};
   1.167 +
   1.168 +/* allocator-independent versions of construct and destroy */
   1.169 +
   1.170 +template<typename Type>
   1.171 +void construct(void* p,const Type& t)
   1.172 +{
   1.173 +  new (p) Type(t);
   1.174 +}
   1.175 +
   1.176 +template<typename Type>
   1.177 +void destroy(const Type* p)
   1.178 +{
   1.179 +  p->~Type();
   1.180 +}
   1.181 +
   1.182 +} /* namespace boost::detail::allocator */
   1.183 +
   1.184 +} /* namespace boost::detail */
   1.185 +
   1.186 +} /* namespace boost */
   1.187 +
   1.188 +#endif