return boost::bind(fn,ob);
}
+template <typename R, typename T>
+boost::function<R()> membind(R (T::* fn)() const,scOBTYPE ob)
+{
+ return boost::bind(fn,ob);
+}
+
// for BOOST_PP_ITERATION() in 2..9 do
#define BOOST_PP_ITERATION_PARAMS_1 (4, (2, 9, SENF_ABSOLUTE_INCLUDE_PATH(Utils/impl/membind.hh), 1))
#include BOOST_PP_ITERATE()
return boost::bind(fn, ob, scPARAMS(_) );
}
+template < typename R, typename T, scPARAMS(typename A) >
+boost::function<R ( scPARAMS(A) )>
+membind(R (T::* fn)( scPARAMS(A) ) const, scOBTYPE ob)
+{
+ return boost::bind(fn, ob, scPARAMS(_) );
+}
+
#undef scPARAMS
#undef scARG
/** \defgroup membind Bound Member Functions
- The membind() family of function templates simplifies the creation
- of simple bound member function pointers:
+ The membind() family of function templates simplifies the creation of simple bound member
+ function pointers:
\code
struct Foo {
int rv = f(1); // Calls foo->test(1)
\endcode
- \idea Make the \a ob argument type an additional P template
- parameter (using call_traits for the exact arg type? Probably
- we'll get deduction problems then) . The only operation this
- object must support is ob->*fn. This would allow the use of
- smart pointers. We should keep the T & version to still support
- ob.*fn use.
+ senf::membind() takes either a pointer or an object as second argument. When passing an object,
+ <em>that object will be copied into the bound member function returned.</em>
+
+ \idea Make the \a ob argument type an additional P template parameter (using call_traits for the
+ exact arg type? Probably we'll get deduction problems then) . The only operation this object
+ must support is ob->*fn. This would allow the use of smart pointers. We should keep the T &
+ version to still support ob.*fn use.
*/
#ifndef HH_SENF_Utils_membind_
return "meth1()";
}
- std::string meth2(int foo, int bar) {
+ std::string meth2(int foo, int bar) const {
std::stringstream s;
s << "meth2(" << foo << "," << bar << ")";
return s.str();