Skip to content

Commit

Permalink
Modernize mem_fn_template.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 4, 2024
1 parent 1acf70f commit 506838b
Showing 1 changed file with 49 additions and 57 deletions.
106 changes: 49 additions & 57 deletions include/boost/bind/mem_fn_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,46 @@ template<class R, class T, class... A> class BOOST_MEM_FN_NAME(mf)

private:

typedef R (BOOST_MEM_FN_CC T::*F) (A...);
F f_;

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...);
}
typedef R (BOOST_MEM_FN_CC T::*Pm) (A...);
Pm pm_;

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
{
return (p->*f_)(a...);
}
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
>

template<class U> R operator()(U & u, A... a) const
R operator()( U&& u, A... a ) const
{
U const * p = 0;
return call(u, p, a...);
return (std::forward<U>( u ).*pm_)( std::forward<A>( a )... );
}

template<class U> R operator()(U const & u, A... a) const
{
U const * p = 0;
return call(u, p, a...);
}
template<class U,
class Ud = typename _mfi::remove_cvref<U>::type,
class E1 = void,
class En = typename std::enable_if<
!(std::is_same<T, Ud>::value || std::is_base_of<T, Ud>::value)
>::type
>

R operator()(T & 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(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_;
}
};

Expand All @@ -82,46 +75,45 @@ template<class R, class T, class... A> class BOOST_MEM_FN_NAME(cmf)

private:

typedef R (BOOST_MEM_FN_CC T::*F) (A...) const;
F f_;

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...);
}
typedef R (BOOST_MEM_FN_CC T::*Pm) (A...) const;
Pm pm_;

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
{
return (p->*f_)(a...);
}
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
>

template<class U> R operator()(U const & u, A... a) const
R operator()( U&& u, A... a ) const
{
U const * p = 0;
return call(u, p, a...);
return (std::forward<U>( u ).*pm_)( std::forward<A>( a )... );
}

R operator()(T const & t, A... a) const
template<class U,
class Ud = typename _mfi::remove_cvref<U>::type,
class E1 = void,
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 (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_;
}
};

0 comments on commit 506838b

Please sign in to comment.