Skip to content

Commit

Permalink
Modernize implementation of _mfi::dm
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 4, 2024
1 parent e41138c commit 56ffdf4
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions include/boost/bind/mem_fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@
// See http://www.boost.org/libs/bind/mem_fn.html for documentation.
//

#include <boost/bind/detail/requires_cxx11.hpp>
#include <boost/get_pointer.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <type_traits>

namespace boost
{

namespace _mfi
{

template<class T> struct remove_cvref: std::remove_cv< typename std::remove_reference<T>::type >
{
};

} // namespace _mfi

namespace _mfi
{

#define BOOST_MEM_FN_NAME(X) X
#define BOOST_MEM_FN_CC

Expand Down Expand Up @@ -152,60 +161,62 @@ template<class R, class T> class dm

private:

typedef R (T::*F);
F f_;
typedef R (T::*Pm);
Pm pm_;

template<class U> R const & call(U & u, T const *) const
{
return (u.*f_);
}
public:

template<class U> R const & call(U & u, void const *) const
{
return (get_pointer(u)->*f_);
}
explicit dm( Pm pm ): pm_( pm ) {}

public:

explicit dm(F f): f_(f) {}
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()(T * p) const
auto operator()( U&& u ) const -> decltype( std::forward<U>( u ).*pm_ )
{
return (p->*f_);
return std::forward<U>( u ).*pm_;
}

R const & operator()(T const * p) const
{
return (p->*f_);
}
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
>

template<class U> R const & operator()(U const & u) const
auto operator()( U&& u ) const -> decltype( get_pointer( std::forward<U>( u ) )->*pm_ )
{
return call(u, &u);
return get_pointer( std::forward<U>( u ) )->*pm_;
}

#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) && !BOOST_WORKAROUND(__MWERKS__, < 0x3200)
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910)

R & operator()(T & t) const
template<class U>
R& operator()( U* u ) const
{
return (t.*f_);
return u->*pm_;
}

R const & operator()(T const & t) const
template<class U>
R const& operator()( U const* u ) const
{
return (t.*f_);
return u->*pm_;
}

#endif

bool operator==(dm const & rhs) const
bool operator==( dm const & rhs ) const
{
return f_ == rhs.f_;
return pm_ == rhs.pm_;
}

bool operator!=(dm const & rhs) const
bool operator!=( dm const & rhs ) const
{
return f_ != rhs.f_;
return pm_ != rhs.pm_;
}
};

Expand Down

0 comments on commit 56ffdf4

Please sign in to comment.