From 26e2c4ba60bca3e84681e5457335e82f99a824e0 Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Wed, 27 May 2009 15:35:25 +0000
Subject: [PATCH] Utils: (membind) Fix weird casting error when binding
 base-class members

---
 Scheduler/TimerSource.cc  |  2 +-
 Utils/Console/Executor.cc |  4 +---
 Utils/impl/membind.hh     | 37 +++++++++++++++++++++++++------------
 Utils/membind.hh          |  4 ++--
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/Scheduler/TimerSource.cc b/Scheduler/TimerSource.cc
index fe6b7d1a3..35e6a5a93 100644
--- a/Scheduler/TimerSource.cc
+++ b/Scheduler/TimerSource.cc
@@ -261,7 +261,7 @@ prefix_ void senf::scheduler::detail::TimerFDTimerSource::reschedule()
         timer.it_value.tv_nsec = ClockService::in_nanoseconds(
             timeout_ - ClockService::seconds(timer.it_value.tv_sec));
     }
-    if (timerfd_settime(timerfd_, TIMER_ABSTIME, &timer, 0)<0)
+    if (timerfd_settime(timerfd_, TFD_TIMER_ABSTIME, &timer, 0)<0)
         SENF_THROW_SYSTEM_EXCEPTION("timerfd_settime()");
 }
 #endif
diff --git a/Utils/Console/Executor.cc b/Utils/Console/Executor.cc
index 1a93b6e95..3bfa19bd4 100644
--- a/Utils/Console/Executor.cc
+++ b/Utils/Console/Executor.cc
@@ -299,9 +299,7 @@ senf::console::Executor::traverseNode(ParseCommandInfo::TokensRange const & path
     catch (UnknownNodeNameException &) {
         throw InvalidPathException(
             senf::stringJoin(
-                senf::make_transform_range(
-                    boost::make_iterator_range(path.begin(), path.end()),
-                    boost::bind(&Token::value, _1)),
+                senf::make_transform_range(path, boost::bind(&Token::value, _1)),
                 "/"));
     }
 }
diff --git a/Utils/impl/membind.hh b/Utils/impl/membind.hh
index 5146e4c4e..8c69a1c46 100644
--- a/Utils/impl/membind.hh
+++ b/Utils/impl/membind.hh
@@ -28,16 +28,22 @@
 #include <boost/preprocessor/repetition/enum_shifted.hpp>
 #include <boost/preprocessor/iteration/iterate.hpp>
 
-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 T>
-boost::function<R()> membind(R (T::* fn)() const,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,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
@@ -49,18 +55,25 @@ boost::function<R()> membind(R (T::* fn)() const,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 (T::* fn)( scPARAMS(A) ), scOBTYPE ob)
+membind(R (T1::* fn)( scPARAMS(A) ) const, T2 const scOBTYPE ob)
 {
-    return boost::bind(fn, ob, scPARAMS(_) );
+    return boost::bind(fn, static_cast<T1 const scOBTYPE>(ob), scPARAMS(_) );
 }
 
-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 (T::* fn)( scPARAMS(A) ) const, 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
diff --git a/Utils/membind.hh b/Utils/membind.hh
index 83613a81b..3b1c4f76c 100644
--- a/Utils/membind.hh
+++ b/Utils/membind.hh
@@ -148,11 +148,11 @@
 
 namespace senf {
 
-#define scOBTYPE T *
+#define scOBTYPE *
 #include "../Utils/impl/membind.hh"
 #undef scOBTYPE
 
-#define scOBTYPE T &
+#define scOBTYPE &
 #include "../Utils/impl/membind.hh"
 #undef scOBTYPE
 
-- 
GitLab