1
0
forked from boostorg/bind

Data member pointers support added.

[SVN r13232]
This commit is contained in:
Peter Dimov
2002-03-20 12:52:40 +00:00
parent 620c803fc1
commit 5bae1b9ad1
5 changed files with 92 additions and 8 deletions

View File

@@ -8,7 +8,7 @@
//
// bind_test.cpp - monolithic test for bind.hpp
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// Permission to copy, use, modify, sell and distribute this software
@@ -372,7 +372,7 @@ void member_function_test()
bind(&X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&X::g8, ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
BOOST_TEST( bind(&X::hash, _1)(x) == 23558 );
}
void member_function_void_test()
@@ -462,7 +462,7 @@ void member_function_void_test()
bind(&V::g8, v, 1, 2, 3, 4, 5, 6, 7, 8)();
bind(&V::g8, ref(v), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( v.hash == 23558 );
BOOST_TEST( bind(&V::hash, _1)(v) == 23558 );
}
void nested_bind_test()

View File

@@ -1355,6 +1355,17 @@ template<class F, class A1, class A2, class A3, class A4, class A5, class A6, cl
#endif
// data member pointers
template<class R, class T, class A1>
_bi::bind_t< R, _mfi::dm<R, T>, typename _bi::list_av_1<A1>::type >
BOOST_BIND(R T::*f, A1 a1)
{
typedef _mfi::dm<R, T> F;
typedef typename _bi::list_av_1<A1>::type list_type;
return _bi::bind_t<R, F, list_type>(F(f), list_type(a1));
}
} // namespace boost
#ifndef BOOST_BIND_NO_PLACEHOLDERS

View File

@@ -8,7 +8,7 @@
//
// mem_fn.hpp - a generalization of std::mem_fun[_ref]
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001 David Abrahams
//
// Permission to copy, use, modify, sell and distribute this software
@@ -187,6 +187,79 @@ namespace _mfi
#endif
// data member support
namespace _mfi
{
template<class R, class T> class dm
{
public:
typedef R const & result_type;
typedef T const * argument_type;
private:
typedef R (T::*F);
F f_;
template<class U> R const & call(U & u, T const *) const
{
return (u.*f_);
}
template<class U> R & call(U & u, T *) const
{
return (u.*f_);
}
template<class U> R const & call(U & u, void const *) const
{
return (get_pointer(u)->*f_);
}
public:
explicit dm(F f): f_(f) {}
R & operator()(T * p) const
{
return (p->*f_);
}
R const & operator()(T const * p) const
{
return (p->*f_);
}
template<class U> R const & operator()(U & u) const
{
return call(u, &u);
}
#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1300)
R & operator()(T & t) const
{
return (t.*f_);
}
#endif
R const & operator()(T const & t) const
{
return (t.*f_);
}
};
} // namespace _mfi
template<class R, class T> _mfi::dm<R, T> mem_fn(R T::*f)
{
return _mfi::dm<R, T>(f);
}
} // namespace boost
#endif // #ifndef BOOST_MEM_FN_HPP_INCLUDED

View File

@@ -8,7 +8,7 @@
//
// mem_fn_derived_test.cpp - tests mem_fn.hpp with derived objects
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
@@ -183,5 +183,5 @@ int main()
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
return detect_errors(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}

View File

@@ -8,7 +8,7 @@
//
// mem_fn_test.cpp - a test for mem_fn.hpp
//
// Copyright (c) 2001 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
@@ -179,5 +179,5 @@ int main()
mem_fn(&X::g8)(pcx, 1, 2, 3, 4, 5, 6, 7, 8);
mem_fn(&X::g8)(sp, 1, 2, 3, 4, 5, 6, 7, 8);
return detect_errors(x.hash == 17610 && sp->hash == 2155);
return detect_errors(mem_fn(&X::hash)(x) == 17610 && mem_fn(&X::hash)(sp) == 2155);
}