Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:44:12

0001 #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED
0002 #define BOOST_BIND_MEM_FN_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 //
0011 // mem_fn.hpp - a generalization of std::mem_fun[_ref]
0012 //
0013 // Copyright 2001-2005, 2024 Peter Dimov
0014 // Copyright 2001 David Abrahams
0015 //
0016 // Distributed under the Boost Software License, Version 1.0. (See
0017 // accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 //
0020 // See http://www.boost.org/libs/bind/mem_fn.html for documentation.
0021 //
0022 
0023 #include <boost/get_pointer.hpp>
0024 #include <boost/config.hpp>
0025 #include <boost/config/workaround.hpp>
0026 #include <type_traits>
0027 
0028 namespace boost
0029 {
0030 
0031 namespace _mfi
0032 {
0033 
0034 template<class T> struct remove_cvref: std::remove_cv< typename std::remove_reference<T>::type >
0035 {
0036 };
0037 
0038 template<class Pm, class R, class T, class... A> class mf
0039 {
0040 public:
0041 
0042     typedef R result_type;
0043 
0044 private:
0045 
0046     Pm pm_;
0047 
0048 public:
0049 
0050     mf( Pm pm ): pm_( pm ) {}
0051 
0052     template<class U,
0053         class Ud = typename _mfi::remove_cvref<U>::type,
0054         class En = typename std::enable_if<
0055             std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value
0056         >::type
0057     >
0058 
0059     R operator()( U&& u, A... a ) const
0060     {
0061         return (std::forward<U>( u ).*pm_)( std::forward<A>( a )... );
0062     }
0063 
0064     template<class U,
0065         class Ud = typename _mfi::remove_cvref<U>::type,
0066         class E1 = void,
0067         class En = typename std::enable_if<
0068             !(std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value)
0069         >::type
0070     >
0071 
0072     R operator()( U&& u, A... a ) const
0073     {
0074         return (get_pointer( std::forward<U>( u ) )->*pm_)( std::forward<A>( a )... );
0075     }
0076 
0077     bool operator==( mf const & rhs ) const
0078     {
0079         return pm_ == rhs.pm_;
0080     }
0081 
0082     bool operator!=( mf const & rhs ) const
0083     {
0084         return pm_ != rhs.pm_;
0085     }
0086 };
0087 
0088 } // namespace _mfi
0089 
0090 //
0091 
0092 template<class R, class T, class... A>
0093 auto mem_fn( R (T::*pmf) (A...) ) -> _mfi::mf<decltype(pmf), R, T, A...>
0094 {
0095     return pmf;
0096 }
0097 
0098 template<class R, class T, class... A>
0099 auto mem_fn( R (T::*pmf) (A...) const ) -> _mfi::mf<decltype(pmf), R, T, A...>
0100 {
0101     return pmf;
0102 }
0103 
0104 #if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED )
0105 
0106 template<class R, class T, class... A>
0107 auto mem_fn( R (T::*pmf) (A...) noexcept ) -> _mfi::mf<decltype(pmf), R, T, A...>
0108 {
0109     return pmf;
0110 }
0111 
0112 template<class R, class T, class... A>
0113 auto mem_fn( R (T::*pmf) (A...) const noexcept ) -> _mfi::mf<decltype(pmf), R, T, A...>
0114 {
0115     return pmf;
0116 }
0117 
0118 #endif // #if defined( __cpp_noexcept_function_type ) || defined( _NOEXCEPT_TYPES_SUPPORTED )
0119 
0120 #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
0121 
0122 template<class R, class T, class... A>
0123 auto mem_fn( R (__cdecl T::*pmf) (A...) ) -> _mfi::mf<decltype(pmf), R, T, A...>
0124 {
0125     return pmf;
0126 }
0127 
0128 template<class R, class T, class... A>
0129 auto mem_fn( R (__cdecl T::*pmf) (A...) const ) -> _mfi::mf<decltype(pmf), R, T, A...>
0130 {
0131     return pmf;
0132 }
0133 
0134 #endif // #if defined(BOOST_MEM_FN_ENABLE_CDECL) && !defined(_M_X64)
0135 
0136 #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
0137 
0138 template<class R, class T, class... A>
0139 auto mem_fn( R (__stdcall T::*pmf) (A...) ) -> _mfi::mf<decltype(pmf), R, T, A...>
0140 {
0141     return pmf;
0142 }
0143 
0144 template<class R, class T, class... A>
0145 auto mem_fn( R (__stdcall T::*pmf) (A...) const ) -> _mfi::mf<decltype(pmf), R, T, A...>
0146 {
0147     return pmf;
0148 }
0149 
0150 #endif // #if defined(BOOST_MEM_FN_ENABLE_STDCALL) && !defined(_M_X64)
0151 
0152 #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
0153 
0154 template<class R, class T, class... A>
0155 auto mem_fn( R (__fastcall T::*pmf) (A...) ) -> _mfi::mf<decltype(pmf), R, T, A...>
0156 {
0157     return pmf;
0158 }
0159 
0160 template<class R, class T, class... A>
0161 auto mem_fn( R (__fastcall T::*pmf) (A...) const ) -> _mfi::mf<decltype(pmf), R, T, A...>
0162 {
0163     return pmf;
0164 }
0165 
0166 #endif // #if defined(BOOST_MEM_FN_ENABLE_FASTCALL) && !defined(_M_X64)
0167 
0168 // data member support
0169 
0170 namespace _mfi
0171 {
0172 
0173 template<class R, class T> class dm
0174 {
0175 public:
0176 
0177     typedef R const & result_type;
0178     typedef T const * argument_type;
0179 
0180 private:
0181 
0182     typedef R (T::*Pm);
0183     Pm pm_;
0184 
0185 public:
0186 
0187     dm( Pm pm ): pm_( pm ) {}
0188 
0189     template<class U,
0190         class Ud = typename _mfi::remove_cvref<U>::type,
0191         class En = typename std::enable_if<
0192             std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value
0193         >::type
0194     >
0195 
0196     auto operator()( U&& u ) const -> decltype( std::forward<U>( u ).*pm_ )
0197     {
0198         return std::forward<U>( u ).*pm_;
0199     }
0200 
0201     template<class U,
0202         class Ud = typename _mfi::remove_cvref<U>::type,
0203         class E1 = void,
0204         class En = typename std::enable_if<
0205             !(std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value)
0206         >::type
0207     >
0208 
0209     auto operator()( U&& u ) const -> decltype( get_pointer( std::forward<U>( u ) )->*pm_ )
0210     {
0211         return get_pointer( std::forward<U>( u ) )->*pm_;
0212     }
0213 
0214 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0215 
0216     template<class U>
0217     R& operator()( U* u ) const
0218     {
0219         return u->*pm_;
0220     }
0221 
0222     template<class U>
0223     R const& operator()( U const* u ) const
0224     {
0225         return u->*pm_;
0226     }
0227 
0228 #endif
0229 
0230     bool operator==( dm const & rhs ) const
0231     {
0232         return pm_ == rhs.pm_;
0233     }
0234 
0235     bool operator!=( dm const & rhs ) const
0236     {
0237         return pm_ != rhs.pm_;
0238     }
0239 };
0240 
0241 } // namespace _mfi
0242 
0243 template<class R, class T,
0244     class E = typename std::enable_if< !std::is_function<R>::value >::type
0245 >
0246 _mfi::dm<R, T> mem_fn( R T::*pm )
0247 {
0248     return pm;
0249 }
0250 
0251 } // namespace boost
0252 
0253 #endif // #ifndef BOOST_BIND_MEM_FN_HPP_INCLUDED