From: g0dil Date: Tue, 17 Mar 2009 14:51:18 +0000 (+0000) Subject: Utils: Allow membind-ing const member functions X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=794b9c2774e19c13ac7eee82ec56fd0f42ede5ff;p=senf.git Utils: Allow membind-ing const member functions git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1156 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/impl/membind.hh b/Utils/impl/membind.hh index 3dad9bf..5146e4c 100644 --- a/Utils/impl/membind.hh +++ b/Utils/impl/membind.hh @@ -34,6 +34,12 @@ boost::function membind(R (T::* fn)(),scOBTYPE ob) return boost::bind(fn,ob); } +template +boost::function 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() @@ -50,6 +56,13 @@ membind(R (T::* fn)( scPARAMS(A) ), scOBTYPE ob) return boost::bind(fn, ob, scPARAMS(_) ); } +template < typename R, typename T, scPARAMS(typename A) > +boost::function +membind(R (T::* fn)( scPARAMS(A) ) const, scOBTYPE ob) +{ + return boost::bind(fn, ob, scPARAMS(_) ); +} + #undef scPARAMS #undef scARG diff --git a/Utils/membind.hh b/Utils/membind.hh index 3ac24d3..c2baf86 100644 --- a/Utils/membind.hh +++ b/Utils/membind.hh @@ -25,8 +25,8 @@ /** \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 { @@ -38,12 +38,13 @@ 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, + that object will be copied into the bound member function returned. + + \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_ diff --git a/Utils/membind.test.cc b/Utils/membind.test.cc index d3517cd..14982ce 100644 --- a/Utils/membind.test.cc +++ b/Utils/membind.test.cc @@ -44,7 +44,7 @@ namespace { 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();