From 22c36ab6b4c1b42a12958d6c88452d039a28b6f8 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 30 Oct 2018 19:50:57 -0700 Subject: Prefer bind over method call in lambda This reduces a layer of indirection since the function can be called directly instead of indirectly accessing it with the lambda. It also makes the instantiation more flexible since it can match callbacks with extra arguments. Tested: Built and run through unit tests. Change-Id: I5317203fa70c027c5e774ed6192952058e35bd81 Signed-off-by: William A. Kennington III --- control/zone.cpp | 5 +++-- monitor/tach_sensor.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/control/zone.cpp b/control/zone.cpp index 1ca0465..17ec5fc 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include #include #include #include @@ -46,8 +47,8 @@ Zone::Zone(Mode mode, _defCeilingSpeed(std::get(def)), _incDelay(std::get(def)), _decInterval(std::get(def)), - _incTimer(event, [this](){ this->incTimerExpired(); }), - _decTimer(event, [this](){ this->decTimerExpired(); }), + _incTimer(event, std::bind(&Zone::incTimerExpired, this)), + _decTimer(event, std::bind(&Zone::decTimerExpired, this)), _eventLoop(event) { auto& fanDefs = std::get(def); diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp index de1affb..26ba3c9 100644 --- a/monitor/tach_sensor.cpp +++ b/monitor/tach_sensor.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ #include +#include #include #include #include "fan.hpp" @@ -88,7 +89,7 @@ TachSensor::TachSensor(Mode mode, _offset(offset), _timeout(timeout), _timerMode(TimerMode::func), - _timer(event, [this, &fan](){ fan.timerExpired(*this); }) + _timer(event, std::bind(&Fan::timerExpired, &fan, std::ref(*this))) { // Start from a known state of functional setFunctional(true); -- cgit v1.2.1