Utils: (membind) Fix weird casting error when binding base-class members
[senf.git] / Utils / impl / membind.hh
index 6b6681c..8c69a1c 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 #include <boost/preprocessor/cat.hpp>
 #include <boost/preprocessor/repetition/enum_shifted.hpp>
 #include <boost/preprocessor/iteration/iterate.hpp>
-#include "../../config.hh"
 
-template <typename R, typename T>
-boost::function<R()> membind(R (T::* fn)(),scOBTYPE ob)
+template <typename R, typename T1, typename T2>
+boost::function<R()> membind(R (T1::* fn)(),T2 scOBTYPE ob)
 {
-    return boost::bind(fn,ob);
+    return boost::bind(fn,static_cast<T1 scOBTYPE>(ob));
+}
+
+template <typename R, typename T1, typename T2>
+boost::function<R()> membind(R (T1::* fn)() const, T2 const scOBTYPE ob)
+{
+    return boost::bind(fn,static_cast<T1 const scOBTYPE>(ob));
+}
+
+template <typename R, typename T1, typename T2>
+boost::function<R()> membind(R (T1::* fn)() const, T2 scOBTYPE ob)
+{
+    return boost::bind(fn,static_cast<T1 const scOBTYPE>(ob));
 }
 
 // for BOOST_PP_ITERATION() in 2..9 do
@@ -44,11 +55,25 @@ boost::function<R()> membind(R (T::* fn)(),scOBTYPE ob)
 #define scARG(z,n,d) BOOST_PP_CAT(d,n)
 #define scPARAMS(d) BOOST_PP_ENUM_SHIFTED(BOOST_PP_ITERATION(),scARG,d)
 
-template < typename R, typename T, scPARAMS(typename A) >
+template < typename R, typename T1, typename T2, scPARAMS(typename A) >
+boost::function<R ( scPARAMS(A) )>
+membind(R (T1::* fn)( scPARAMS(A) ), T2 scOBTYPE ob)
+{
+    return boost::bind(fn, static_cast<T1 scOBTYPE>(ob), scPARAMS(_) );
+}
+
+template < typename R, typename T1, typename T2, scPARAMS(typename A) >
+boost::function<R ( scPARAMS(A) )>
+membind(R (T1::* fn)( scPARAMS(A) ) const, T2 const scOBTYPE ob)
+{
+    return boost::bind(fn, static_cast<T1 const scOBTYPE>(ob), scPARAMS(_) );
+}
+
+template < typename R, typename T1, typename T2, scPARAMS(typename A) >
 boost::function<R ( scPARAMS(A) )>
-membind(R (T::* fn)( scPARAMS(A) ), scOBTYPE ob)
+membind(R (T1::* fn)( scPARAMS(A) ) const, T2 scOBTYPE ob)
 {
-    return boost::bind(fn, ob, scPARAMS(_) );
+    return boost::bind(fn, static_cast<T1 const scOBTYPE>(ob), scPARAMS(_) );
 }
 
 #undef scPARAMS