1
0
forked from boostorg/bind

Modernize mem_fn_template.hpp

This commit is contained in:
Peter Dimov
2024-01-04 19:11:35 +02:00
parent 1acf70f920
commit 506838badd

View File

@@ -22,53 +22,46 @@ public:
private: private:
typedef R (BOOST_MEM_FN_CC T::*F) (A...); typedef R (BOOST_MEM_FN_CC T::*Pm) (A...);
F f_; Pm pm_;
template<class U, class... B> R call(U & u, T const *, B&... b) const
{
return (u.*f_)(b...);
}
template<class U, class... B> R call(U & u, void const *, B&... b) const
{
return (get_pointer(u)->*f_)(b...);
}
public: public:
explicit BOOST_MEM_FN_NAME(mf)(F f): f_(f) {} explicit BOOST_MEM_FN_NAME(mf)( Pm pm ): pm_( pm ) {}
R operator()(T * p, A... a) const template<class U,
class Ud = typename _mfi::remove_cvref<U>::type,
class En = typename std::enable_if<
std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value
>::type
>
R operator()( U&& u, A... a ) const
{ {
return (p->*f_)(a...); return (std::forward<U>( u ).*pm_)( std::forward<A>( a )... );
} }
template<class U> R operator()(U & u, A... a) const template<class U,
{ class Ud = typename _mfi::remove_cvref<U>::type,
U const * p = 0; class E1 = void,
return call(u, p, a...); class En = typename std::enable_if<
} !(std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value)
>::type
>
template<class U> R operator()(U const & u, A... a) const R operator()( U&& u, A... a ) const
{ {
U const * p = 0; return (get_pointer( std::forward<U>( u ) )->*pm_)( std::forward<A>( a )... );
return call(u, p, a...);
}
R operator()(T & t, A... a) const
{
return (t.*f_)(a...);
} }
bool operator==( BOOST_MEM_FN_NAME(mf) const & rhs ) const bool operator==( BOOST_MEM_FN_NAME(mf) const & rhs ) const
{ {
return f_ == rhs.f_; return pm_ == rhs.pm_;
} }
bool operator!=( BOOST_MEM_FN_NAME(mf) const & rhs ) const bool operator!=( BOOST_MEM_FN_NAME(mf) const & rhs ) const
{ {
return f_ != rhs.f_; return pm_ != rhs.pm_;
} }
}; };
@@ -82,46 +75,45 @@ public:
private: private:
typedef R (BOOST_MEM_FN_CC T::*F) (A...) const; typedef R (BOOST_MEM_FN_CC T::*Pm) (A...) const;
F f_; Pm pm_;
template<class U, class... B> R call(U & u, T const *, B&... b) const
{
return (u.*f_)(b...);
}
template<class U, class... B> R call(U & u, void const *, B&... b) const
{
return (get_pointer(u)->*f_)(b...);
}
public: public:
explicit BOOST_MEM_FN_NAME(cmf)(F f): f_(f) {} explicit BOOST_MEM_FN_NAME(cmf)( Pm pm ): pm_( pm ) {}
R operator()(T const * p, A... a) const template<class U,
class Ud = typename _mfi::remove_cvref<U>::type,
class En = typename std::enable_if<
std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value
>::type
>
R operator()( U&& u, A... a ) const
{ {
return (p->*f_)(a...); return (std::forward<U>( u ).*pm_)( std::forward<A>( a )... );
} }
template<class U> R operator()(U const & u, A... a) const template<class U,
{ class Ud = typename _mfi::remove_cvref<U>::type,
U const * p = 0; class E1 = void,
return call(u, p, a...); class En = typename std::enable_if<
} !(std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value)
>::type
>
R operator()(T const & t, A... a) const R operator()( U&& u, A... a ) const
{ {
return (t.*f_)(a...); return (get_pointer( std::forward<U>( u ) )->*pm_)( std::forward<A>( a )... );
} }
bool operator==( BOOST_MEM_FN_NAME(cmf) const & rhs ) const bool operator==( BOOST_MEM_FN_NAME(cmf) const & rhs ) const
{ {
return f_ == rhs.f_; return pm_ == rhs.pm_;
} }
bool operator!=( BOOST_MEM_FN_NAME(cmf) const & rhs ) const bool operator!=( BOOST_MEM_FN_NAME(cmf) const & rhs ) const
{ {
return f_ != rhs.f_; return pm_ != rhs.pm_;
} }
}; };