1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/multi_index/mem_fun.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,222 @@
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_MEM_FUN_HPP
1.13 +#define BOOST_MULTI_INDEX_MEM_FUN_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> /* keep it first to prevent nasty warns in MSVC */
1.20 +#include <boost/mpl/if.hpp>
1.21 +#include <boost/type_traits/remove_reference.hpp>
1.22 +#include <boost/utility/enable_if.hpp>
1.23 +
1.24 +#if !defined(BOOST_NO_SFINAE)
1.25 +#include <boost/type_traits/is_convertible.hpp>
1.26 +#endif
1.27 +
1.28 +namespace boost{
1.29 +
1.30 +template<class T> class reference_wrapper; /* fwd decl. */
1.31 +
1.32 +namespace multi_index{
1.33 +
1.34 +/* mem_fun implements a read-only key extractor based on a given non-const
1.35 + * member function of a class.
1.36 + * const_mem_fun does the same for const member functions.
1.37 + * Additionally, mem_fun and const_mem_fun are overloaded to support
1.38 + * referece_wrappers of T and "chained pointers" to T's. By chained pointer
1.39 + * to T we mean a type P such that, given a p of Type P
1.40 + * *...n...*x is convertible to T&, for some n>=1.
1.41 + * Examples of chained pointers are raw and smart pointers, iterators and
1.42 + * arbitrary combinations of these (vg. T** or auto_ptr<T*>.)
1.43 + */
1.44 +
1.45 +/* NB. Some overloads of operator() have an extra dummy parameter int=0.
1.46 + * This disambiguator serves several purposes:
1.47 + * - Without it, MSVC++ 6.0 incorrectly regards some overloads as
1.48 + * specializations of a previous member function template.
1.49 + * - MSVC++ 6.0/7.0 seem to incorrectly treat some different memfuns
1.50 + * as if they have the same signature.
1.51 + * - If remove_const is broken due to lack of PTS, int=0 avoids the
1.52 + * declaration of memfuns with identical signature.
1.53 + */
1.54 +
1.55 +template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()const>
1.56 +struct const_mem_fun
1.57 +{
1.58 + typedef typename remove_reference<Type>::type result_type;
1.59 +
1.60 + template<typename ChainedPtr>
1.61 +
1.62 +#if !defined(BOOST_NO_SFINAE)
1.63 + typename disable_if<
1.64 + is_convertible<const ChainedPtr&,const Class&>,Type>::type
1.65 +#else
1.66 + Type
1.67 +#endif
1.68 +
1.69 + operator()(const ChainedPtr& x)const
1.70 + {
1.71 + return operator()(*x);
1.72 + }
1.73 +
1.74 + Type operator()(const Class& x)const
1.75 + {
1.76 + return (x.*PtrToMemberFunction)();
1.77 + }
1.78 +
1.79 + Type operator()(const reference_wrapper<const Class>& x)const
1.80 + {
1.81 + return operator()(x.get());
1.82 + }
1.83 +
1.84 + Type operator()(const reference_wrapper<Class>& x,int=0)const
1.85 + {
1.86 + return operator()(x.get());
1.87 + }
1.88 +};
1.89 +
1.90 +template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()>
1.91 +struct mem_fun
1.92 +{
1.93 + typedef typename remove_reference<Type>::type result_type;
1.94 +
1.95 + template<typename ChainedPtr>
1.96 +
1.97 +#if !defined(BOOST_NO_SFINAE)
1.98 + typename disable_if<
1.99 + is_convertible<ChainedPtr&,Class&>,Type>::type
1.100 +#else
1.101 + Type
1.102 +#endif
1.103 +
1.104 + operator()(const ChainedPtr& x)const
1.105 + {
1.106 + return operator()(*x);
1.107 + }
1.108 +
1.109 + Type operator()(Class& x)const
1.110 + {
1.111 + return (x.*PtrToMemberFunction)();
1.112 + }
1.113 +
1.114 + Type operator()(const reference_wrapper<Class>& x)const
1.115 + {
1.116 + return operator()(x.get());
1.117 + }
1.118 +};
1.119 +
1.120 +/* MSVC++ 6.0 has problems with const member functions as non-type template
1.121 + * parameters, somehow it takes them as non-const. mem_fun_explicit workarounds
1.122 + * this defficiency by accepting an extra type parameter that specifies the
1.123 + * signature of he member function. The workaround was found at:
1.124 + * Daniel, C.:"Re: weird typedef problem in VC",
1.125 + * news:microsoft.public.vc.language, 21st nov 2002,
1.126 + * http://groups.google.com/groups?
1.127 + * hl=en&lr=&ie=UTF-8&selm=ukwvg3O0BHA.1512%40tkmsftngp05
1.128 + */
1.129 +
1.130 +template<
1.131 + class Class,typename Type,
1.132 + typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction>
1.133 +struct const_mem_fun_explicit
1.134 +{
1.135 + typedef typename remove_reference<Type>::type result_type;
1.136 +
1.137 + template<typename ChainedPtr>
1.138 +
1.139 +#if !defined(BOOST_NO_SFINAE)
1.140 + typename disable_if<
1.141 + is_convertible<const ChainedPtr&,const Class&>,Type>::type
1.142 +#else
1.143 + Type
1.144 +#endif
1.145 +
1.146 + operator()(const ChainedPtr& x)const
1.147 + {
1.148 + return operator()(*x);
1.149 + }
1.150 +
1.151 + Type operator()(const Class& x)const
1.152 + {
1.153 + return (x.*PtrToMemberFunction)();
1.154 + }
1.155 +
1.156 + Type operator()(const reference_wrapper<const Class>& x)const
1.157 + {
1.158 + return operator()(x.get());
1.159 + }
1.160 +
1.161 + Type operator()(const reference_wrapper<Class>& x,int=0)const
1.162 + {
1.163 + return operator()(x.get());
1.164 + }
1.165 +};
1.166 +
1.167 +template<
1.168 + class Class,typename Type,
1.169 + typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction>
1.170 +struct mem_fun_explicit
1.171 +{
1.172 + typedef typename remove_reference<Type>::type result_type;
1.173 +
1.174 + template<typename ChainedPtr>
1.175 +
1.176 +#if !defined(BOOST_NO_SFINAE)
1.177 + typename disable_if<
1.178 + is_convertible<ChainedPtr&,Class&>,Type>::type
1.179 +#else
1.180 + Type
1.181 +#endif
1.182 +
1.183 + operator()(const ChainedPtr& x)const
1.184 + {
1.185 + return operator()(*x);
1.186 + }
1.187 +
1.188 + Type operator()(Class& x)const
1.189 + {
1.190 + return (x.*PtrToMemberFunction)();
1.191 + }
1.192 +
1.193 + Type operator()(const reference_wrapper<Class>& x)const
1.194 + {
1.195 + return operator()(x.get());
1.196 + }
1.197 +};
1.198 +
1.199 +/* BOOST_MULTI_INDEX_CONST_MEM_FUN and BOOST_MULTI_INDEX_MEM_FUN resolve to
1.200 + * mem_fun_explicit for MSVC++ 6.0 and to [const_]mem_fun otherwise.
1.201 + */
1.202 +
1.203 +#if defined(BOOST_MSVC)&&(BOOST_MSVC<1300)
1.204 +
1.205 +#define BOOST_MULTI_INDEX_CONST_MEM_FUN(Class,Type,MemberFunName) \
1.206 +::boost::multi_index::const_mem_fun_explicit<\
1.207 + Class,Type,Type (Class::*)()const,&Class::MemberFunName >
1.208 +#define BOOST_MULTI_INDEX_MEM_FUN(Class,Type,MemberFunName) \
1.209 +::boost::multi_index::mem_fun_explicit<\
1.210 + Class,Type,Type (Class::*)(),&Class::MemberFunName >
1.211 +
1.212 +#else
1.213 +
1.214 +#define BOOST_MULTI_INDEX_CONST_MEM_FUN(Class,Type,MemberFunName) \
1.215 +::boost::multi_index::const_mem_fun< Class,Type,&Class::MemberFunName >
1.216 +#define BOOST_MULTI_INDEX_MEM_FUN(Class,Type,MemberFunName) \
1.217 +::boost::multi_index::mem_fun< Class,Type,&Class::MemberFunName >
1.218 +
1.219 +#endif
1.220 +
1.221 +} /* namespace multi_index */
1.222 +
1.223 +} /* namespace boost */
1.224 +
1.225 +#endif