Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:11

0001 /* Copyright 2003-2022 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/multi_index for library home page.
0007  */
0008 
0009 #ifndef BOOST_MULTI_INDEX_MEM_FUN_HPP
0010 #define BOOST_MULTI_INDEX_MEM_FUN_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0017 #include <boost/core/enable_if.hpp>
0018 #include <boost/mpl/if.hpp>
0019 #include <boost/type_traits/remove_reference.hpp>
0020 
0021 #if !defined(BOOST_NO_SFINAE)
0022 #include <boost/type_traits/is_convertible.hpp>
0023 #endif
0024 
0025 namespace boost{
0026 
0027 template<class T> class reference_wrapper; /* fwd decl. */
0028 
0029 namespace multi_index{
0030 
0031 /* mem_fun implements a read-only key extractor based on a given non-const
0032  * member function of a class.
0033  * Also, the following variations are provided:
0034  *   const_mem_fun:    const member functions
0035  *   volatile_mem_fun: volatile member functions
0036  *   cv_mem_fun:       const volatile member functions
0037  *   ref_mem_fun:      ref-qualifed member functions (C++11)
0038  *   cref_mem_fun:     const ref-qualifed member functions (C++11)
0039  *   vref_mem_fun:     volatile ref-qualifed member functions (C++11)
0040  *   cvref_mem_fun:    const volatile ref-qualifed member functions (C++11)
0041  *
0042  * All of these classes are overloaded to support boost::referece_wrappers
0043  * of T and "chained pointers" to T's. By chained pointer to T we mean a type
0044  * P such that, given a p of Type P
0045  *   *...n...*x is convertible to T&, for some n>=1.
0046  * Examples of chained pointers are raw and smart pointers, iterators and
0047  * arbitrary combinations of these (vg. T** or unique_ptr<T*>.)
0048  */
0049 
0050 namespace detail{
0051 
0052 template<
0053   class Class,typename Type,
0054   typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction
0055 >
0056 struct const_mem_fun_impl
0057 {
0058   typedef typename remove_reference<Type>::type result_type;
0059 
0060   template<typename ChainedPtr>
0061 
0062 #if !defined(BOOST_NO_SFINAE)
0063   typename disable_if<
0064     is_convertible<const ChainedPtr&,const Class&>,Type>::type
0065 #else
0066   Type
0067 #endif
0068 
0069   operator()(const ChainedPtr& x)const
0070   {
0071     return operator()(*x);
0072   }
0073 
0074   Type operator()(const Class& x)const
0075   {
0076     return (x.*PtrToMemberFunction)();
0077   }
0078 
0079   Type operator()(const reference_wrapper<const Class>& x)const
0080   { 
0081     return operator()(x.get());
0082   }
0083 
0084   Type operator()(const reference_wrapper<Class>& x)const
0085   { 
0086     return operator()(x.get());
0087   }
0088 };
0089 
0090 template<
0091   class Class,typename Type,
0092   typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction
0093 >
0094 struct mem_fun_impl
0095 {
0096   typedef typename remove_reference<Type>::type result_type;
0097 
0098   template<typename ChainedPtr>
0099 
0100 #if !defined(BOOST_NO_SFINAE)
0101   typename disable_if<
0102     is_convertible<ChainedPtr&,Class&>,Type>::type
0103 #else
0104   Type
0105 #endif
0106 
0107   operator()(const ChainedPtr& x)const
0108   {
0109     return operator()(*x);
0110   }
0111 
0112   Type operator()(Class& x)const
0113   {
0114     return (x.*PtrToMemberFunction)();
0115   }
0116 
0117   Type operator()(const reference_wrapper<Class>& x)const
0118   { 
0119     return operator()(x.get());
0120   }
0121 };
0122 
0123 } /* namespace multi_index::detail */
0124 
0125 template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()const>
0126 struct const_mem_fun:detail::const_mem_fun_impl<
0127   Class,Type,Type (Class::*)()const,PtrToMemberFunction
0128 >{};
0129 
0130 template<
0131   class Class,typename Type,
0132   Type (Class::*PtrToMemberFunction)()const volatile
0133 >
0134 struct cv_mem_fun:detail::const_mem_fun_impl<
0135   Class,Type,Type (Class::*)()const volatile,PtrToMemberFunction
0136 >{};
0137 
0138 template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()>
0139 struct mem_fun:
0140   detail::mem_fun_impl<Class,Type,Type (Class::*)(),PtrToMemberFunction>{};
0141 
0142 template<
0143   class Class,typename Type,Type (Class::*PtrToMemberFunction)()volatile
0144 >
0145 struct volatile_mem_fun:detail::mem_fun_impl<
0146   Class,Type,Type (Class::*)()volatile,PtrToMemberFunction
0147 >{};
0148 
0149 #if !defined(BOOST_NO_CXX11_REF_QUALIFIERS)
0150 
0151 template<
0152   class Class,typename Type,Type (Class::*PtrToMemberFunction)()const&
0153 >
0154 struct cref_mem_fun:detail::const_mem_fun_impl<
0155   Class,Type,Type (Class::*)()const&,PtrToMemberFunction
0156 >{};
0157 
0158 template<
0159   class Class,typename Type,
0160   Type (Class::*PtrToMemberFunction)()const volatile&
0161 >
0162 struct cvref_mem_fun:detail::const_mem_fun_impl<
0163   Class,Type,Type (Class::*)()const volatile&,PtrToMemberFunction
0164 >{};
0165 
0166 template<class Class,typename Type,Type (Class::*PtrToMemberFunction)()&>
0167 struct ref_mem_fun:
0168   detail::mem_fun_impl<Class,Type,Type (Class::*)()&,PtrToMemberFunction>{};
0169 
0170 template<
0171   class Class,typename Type,Type (Class::*PtrToMemberFunction)()volatile&
0172 >
0173 struct vref_mem_fun:detail::mem_fun_impl<
0174   Class,Type,Type (Class::*)()volatile&,PtrToMemberFunction
0175 >{};
0176 
0177 #endif
0178 
0179 /* MSVC++ 6.0 has problems with const member functions as non-type template
0180  * parameters, somehow it takes them as non-const. const_mem_fun_explicit
0181  * workarounds this deficiency by accepting an extra type parameter that
0182  * specifies the signature of the member function. The workaround was found at:
0183  *   Daniel, C.:"Re: weird typedef problem in VC",
0184  *   news:microsoft.public.vc.language, 21st nov 2002, 
0185  *   http://groups.google.com/groups?
0186  *     hl=en&lr=&ie=UTF-8&selm=ukwvg3O0BHA.1512%40tkmsftngp05
0187  *
0188  * MSVC++ 6.0 support has been dropped and [const_]mem_fun_explicit is
0189  * deprecated.
0190  */
0191 
0192 template<
0193   class Class,typename Type,
0194   typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction
0195 >
0196 struct const_mem_fun_explicit
0197 {
0198   typedef typename remove_reference<Type>::type result_type;
0199 
0200   template<typename ChainedPtr>
0201 
0202 #if !defined(BOOST_NO_SFINAE)
0203   typename disable_if<
0204     is_convertible<const ChainedPtr&,const Class&>,Type>::type
0205 #else
0206   Type
0207 #endif
0208 
0209   operator()(const ChainedPtr& x)const
0210   {
0211     return operator()(*x);
0212   }
0213 
0214   Type operator()(const Class& x)const
0215   {
0216     return (x.*PtrToMemberFunction)();
0217   }
0218 
0219   Type operator()(const reference_wrapper<const Class>& x)const
0220   { 
0221     return operator()(x.get());
0222   }
0223 
0224   Type operator()(const reference_wrapper<Class>& x)const
0225   { 
0226     return operator()(x.get());
0227   }
0228 };
0229 
0230 template<
0231   class Class,typename Type,
0232   typename PtrToMemberFunctionType,PtrToMemberFunctionType PtrToMemberFunction
0233 >
0234 struct mem_fun_explicit
0235 {
0236   typedef typename remove_reference<Type>::type result_type;
0237 
0238   template<typename ChainedPtr>
0239 
0240 #if !defined(BOOST_NO_SFINAE)
0241   typename disable_if<
0242     is_convertible<ChainedPtr&,Class&>,Type>::type
0243 #else
0244   Type
0245 #endif
0246 
0247   operator()(const ChainedPtr& x)const
0248   {
0249     return operator()(*x);
0250   }
0251 
0252   Type operator()(Class& x)const
0253   {
0254     return (x.*PtrToMemberFunction)();
0255   }
0256 
0257   Type operator()(const reference_wrapper<Class>& x)const
0258   { 
0259     return operator()(x.get());
0260   }
0261 };
0262 
0263 /* BOOST_MULTI_INDEX_CONST_MEM_FUN and BOOST_MULTI_INDEX_MEM_FUN used to
0264  * resolve to [const_]mem_fun_explicit for MSVC++ 6.0 and to
0265  * [const_]mem_fun otherwise. Support for this compiler having been dropped,
0266  * they are now just wrappers over [const_]mem_fun kept for backwards-
0267  * compatibility reasons.
0268  */
0269 
0270 #define BOOST_MULTI_INDEX_CONST_MEM_FUN(Class,Type,MemberFunName) \
0271 ::boost::multi_index::const_mem_fun< Class,Type,&Class::MemberFunName >
0272 #define BOOST_MULTI_INDEX_MEM_FUN(Class,Type,MemberFunName) \
0273 ::boost::multi_index::mem_fun< Class,Type,&Class::MemberFunName >
0274 
0275 } /* namespace multi_index */
0276 
0277 } /* namespace boost */
0278 
0279 #endif