epoc32/include/stdapis/boost/multi_index/identity.hpp
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/multi_index/identity.hpp	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/* Copyright 2003-2006 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 http://www.boost.org/libs/multi_index for library home page.
    1.10 + */
    1.11 +
    1.12 +#ifndef BOOST_MULTI_INDEX_IDENTITY_HPP
    1.13 +#define BOOST_MULTI_INDEX_IDENTITY_HPP
    1.14 +
    1.15 +#if defined(_MSC_VER)&&(_MSC_VER>=1200)
    1.16 +#pragma once
    1.17 +#endif
    1.18 +
    1.19 +#include <boost/config.hpp>
    1.20 +#include <boost/mpl/if.hpp>
    1.21 +#include <boost/multi_index/identity_fwd.hpp>
    1.22 +#include <boost/type_traits/is_const.hpp>
    1.23 +#include <boost/type_traits/remove_const.hpp>
    1.24 +#include <boost/utility/enable_if.hpp>
    1.25 +
    1.26 +#if !defined(BOOST_NO_SFINAE)
    1.27 +#include <boost/type_traits/is_convertible.hpp>
    1.28 +#endif
    1.29 +
    1.30 +namespace boost{
    1.31 +
    1.32 +template<class Type> class reference_wrapper; /* fwd decl. */
    1.33 +
    1.34 +namespace multi_index{
    1.35 +
    1.36 +namespace detail{
    1.37 +
    1.38 +/* identity is a do-nothing key extractor that returns the [const] Type&
    1.39 + * object passed.
    1.40 + * Additionally, identity is overloaded to support referece_wrappers
    1.41 + * of Type and "chained pointers" to Type's. By chained pointer to Type we
    1.42 + * mean a  type  P such that, given a p of type P
    1.43 + *   *...n...*x is convertible to Type&, for some n>=1.
    1.44 + * Examples of chained pointers are raw and smart pointers, iterators and
    1.45 + * arbitrary combinations of these (vg. Type** or auto_ptr<Type*>.)
    1.46 + */
    1.47 +
    1.48 +/* NB. Some overloads of operator() have an extra dummy parameter int=0.
    1.49 + * This disambiguator serves several purposes:
    1.50 + *  - Without it, MSVC++ 6.0 incorrectly regards some overloads as
    1.51 + *    specializations of a previous member function template.
    1.52 + *  - MSVC++ 6.0/7.0 seem to incorrectly treat some different memfuns
    1.53 + *    as if they have the same signature.
    1.54 + *  - If remove_const is broken due to lack of PTS, int=0 avoids the
    1.55 + *    declaration of memfuns with identical signature.
    1.56 + */
    1.57 +
    1.58 +template<typename Type>
    1.59 +struct const_identity_base
    1.60 +{
    1.61 +  typedef Type result_type;
    1.62 +
    1.63 +  template<typename ChainedPtr>
    1.64 +
    1.65 +#if !defined(BOOST_NO_SFINAE)
    1.66 +  typename disable_if<is_convertible<const ChainedPtr&,Type&>,Type&>::type
    1.67 +#else
    1.68 +  Type&
    1.69 +#endif 
    1.70 +  
    1.71 +  operator()(const ChainedPtr& x)const
    1.72 +  {
    1.73 +    return operator()(*x);
    1.74 +  }
    1.75 +
    1.76 +  Type& operator()(Type& x)const
    1.77 +  {
    1.78 +    return x;
    1.79 +  }
    1.80 +
    1.81 +  Type& operator()(const reference_wrapper<Type>& x)const
    1.82 +  { 
    1.83 +    return x.get();
    1.84 +  }
    1.85 +
    1.86 +  Type& operator()(
    1.87 +    const reference_wrapper<typename remove_const<Type>::type>& x,int=0)const
    1.88 +  { 
    1.89 +    return x.get();
    1.90 +  }
    1.91 +};
    1.92 +
    1.93 +template<typename Type>
    1.94 +struct non_const_identity_base
    1.95 +{
    1.96 +  typedef Type result_type;
    1.97 +
    1.98 +  /* templatized for pointer-like types */
    1.99 +  
   1.100 +  template<typename ChainedPtr>
   1.101 +
   1.102 +#if !defined(BOOST_NO_SFINAE)
   1.103 +  typename disable_if<
   1.104 +    is_convertible<const ChainedPtr&,const Type&>,Type&>::type
   1.105 +#else
   1.106 +  Type&
   1.107 +#endif 
   1.108 +    
   1.109 +  operator()(const ChainedPtr& x)const
   1.110 +  {
   1.111 +    return operator()(*x);
   1.112 +  }
   1.113 +
   1.114 +  const Type& operator()(const Type& x,int=0)const
   1.115 +  {
   1.116 +    return x;
   1.117 +  }
   1.118 +
   1.119 +  Type& operator()(Type& x)const
   1.120 +  {
   1.121 +    return x;
   1.122 +  }
   1.123 +
   1.124 +  const Type& operator()(const reference_wrapper<const Type>& x,int=0)const
   1.125 +  { 
   1.126 +    return x.get();
   1.127 +  }
   1.128 +
   1.129 +  Type& operator()(const reference_wrapper<Type>& x)const
   1.130 +  { 
   1.131 +    return x.get();
   1.132 +  }
   1.133 +};
   1.134 +
   1.135 +} /* namespace multi_index::detail */
   1.136 +
   1.137 +template<class Type>
   1.138 +struct identity:
   1.139 +  mpl::if_c<
   1.140 +    is_const<Type>::value,
   1.141 +    detail::const_identity_base<Type>,detail::non_const_identity_base<Type>
   1.142 +  >::type
   1.143 +{
   1.144 +};
   1.145 +
   1.146 +} /* namespace multi_index */
   1.147 +
   1.148 +} /* namespace boost */
   1.149 +
   1.150 +#endif