Back to home page

EIC code displayed by LXR

 
 

    


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

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_GLOBAL_FUN_HPP
0010 #define BOOST_MULTI_INDEX_GLOBAL_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/detail/workaround.hpp>
0019 #include <boost/mpl/if.hpp>
0020 #include <boost/type_traits/is_const.hpp>
0021 #include <boost/type_traits/is_reference.hpp>
0022 #include <boost/type_traits/remove_const.hpp>
0023 #include <boost/type_traits/remove_reference.hpp>
0024 
0025 #if !defined(BOOST_NO_SFINAE)
0026 #include <boost/type_traits/is_convertible.hpp>
0027 #endif
0028 
0029 namespace boost{
0030 
0031 template<class T> class reference_wrapper; /* fwd decl. */
0032 
0033 namespace multi_index{
0034 
0035 namespace detail{
0036 
0037 /* global_fun is a read-only key extractor from Value based on a given global
0038  * (or static member) function with signature:
0039  *
0040  *   Type f([const] Value [&]);
0041  *
0042  * Additionally, global_fun  and const_global_fun are overloaded to support
0043  * referece_wrappers of Value and "chained pointers" to Value's. By chained
0044  * pointer to T we  mean a type 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 template<class Value,typename Type,Type (*PtrToFunction)(Value)>
0051 struct const_ref_global_fun_base
0052 {
0053   typedef typename remove_reference<Type>::type result_type;
0054 
0055   template<typename ChainedPtr>
0056 
0057 #if !defined(BOOST_NO_SFINAE)
0058   typename disable_if<
0059     is_convertible<const ChainedPtr&,Value>,Type>::type
0060 #else
0061   Type
0062 #endif
0063 
0064   operator()(const ChainedPtr& x)const
0065   {
0066     return operator()(*x);
0067   }
0068 
0069   Type operator()(Value x)const
0070   {
0071     return PtrToFunction(x);
0072   }
0073 
0074   Type operator()(
0075     const reference_wrapper<
0076       typename remove_reference<Value>::type>& x)const
0077   { 
0078     return operator()(x.get());
0079   }
0080 
0081   Type operator()(
0082     const reference_wrapper<
0083       typename remove_const<
0084         typename remove_reference<Value>::type>::type>& x
0085 
0086 #if BOOST_WORKAROUND(BOOST_MSVC,==1310)
0087 /* http://lists.boost.org/Archives/boost/2015/10/226135.php */
0088     ,int=0
0089 #endif
0090 
0091   )const
0092   { 
0093     return operator()(x.get());
0094   }
0095 };
0096 
0097 template<class Value,typename Type,Type (*PtrToFunction)(Value)>
0098 struct non_const_ref_global_fun_base
0099 {
0100   typedef typename remove_reference<Type>::type result_type;
0101 
0102   template<typename ChainedPtr>
0103 
0104 #if !defined(BOOST_NO_SFINAE)
0105   typename disable_if<
0106     is_convertible<ChainedPtr&,Value>,Type>::type
0107 #else
0108   Type
0109 #endif
0110 
0111   operator()(const ChainedPtr& x)const
0112   {
0113     return operator()(*x);
0114   }
0115 
0116   Type operator()(Value x)const
0117   {
0118     return PtrToFunction(x);
0119   }
0120 
0121   Type operator()(
0122     const reference_wrapper<
0123       typename remove_reference<Value>::type>& x)const
0124   { 
0125     return operator()(x.get());
0126   }
0127 };
0128 
0129 template<class Value,typename Type,Type (*PtrToFunction)(Value)>
0130 struct non_ref_global_fun_base
0131 {
0132   typedef typename remove_reference<Type>::type result_type;
0133 
0134   template<typename ChainedPtr>
0135 
0136 #if !defined(BOOST_NO_SFINAE)
0137   typename disable_if<
0138     is_convertible<const ChainedPtr&,const Value&>,Type>::type
0139 #else
0140   Type
0141 #endif
0142 
0143   operator()(const ChainedPtr& x)const
0144   {
0145     return operator()(*x);
0146   }
0147 
0148   Type operator()(const Value& x)const
0149   {
0150     return PtrToFunction(x);
0151   }
0152 
0153   Type operator()(const reference_wrapper<const Value>& x)const
0154   { 
0155     return operator()(x.get());
0156   }
0157 
0158   Type operator()(
0159     const reference_wrapper<typename remove_const<Value>::type>& x)const
0160   { 
0161     return operator()(x.get());
0162   }
0163 };
0164 
0165 } /* namespace multi_index::detail */
0166 
0167 template<class Value,typename Type,Type (*PtrToFunction)(Value)>
0168 struct global_fun:
0169   mpl::if_c<
0170     is_reference<Value>::value,
0171     typename mpl::if_c<
0172       is_const<typename remove_reference<Value>::type>::value,
0173       detail::const_ref_global_fun_base<Value,Type,PtrToFunction>,
0174       detail::non_const_ref_global_fun_base<Value,Type,PtrToFunction>
0175     >::type,
0176     detail::non_ref_global_fun_base<Value,Type,PtrToFunction>
0177   >::type
0178 {
0179 };
0180 
0181 } /* namespace multi_index */
0182 
0183 } /* namespace boost */
0184 
0185 #endif