paizza paizza - 4 months ago 9
C++ Question

How to pass only second argument of a bind function?

I'm using a generic EventEmitter instance:

EventEmitter mEventHandler;


So I've defined this bind:

function<void(int, double)> onSetMin = bind(&ILFO::SetMin, this, placeholders::_2);
mEventHandler.on(kParamID, onSetMin);


and the
on
such as:

mEventHandler.emit(paramID, someInt, someDouble);


which is "generic" as said, and set 2 params. But my specific function
SetMin
need just one param (which would be
someDouble
in this case):

void ILFO::SetMin(double min);


How would you just pass second paramter from bind?

Answer

Easier to use a lambda for your problem I think:

function<void(int, double)> onSetMin = [this](int dummy, double d) { SetMin(d); };
mEventHandler.on(kParamID, onSetMin);