The project has some callback functions:
using fn = std::function<void()>;
The callback function is a parameter of the class X's constructor:
class X(fn).
X x([](){})
X.fn()
I would like to introduce another type of callback function to indicate id, so I need another type:
using xfn = std::function<void(int)>;
Is there a possible way to change the parameter so that it could support both types of function.
The project already contains many code with the first type of function. They are called with X.fn()
. I am trying to make class X support X.fn(100)
. So people can both call X.fn()
and X.fn(100)
, with the same name fn. (I don't want it to be a new member with a different name), just like a function with default value. fn() = fn(int val=100)
I want to introduce:
X x([](int x){})
X.fn(100)
Is it possible to change the class constructor to a more general prototype-function like
class X(genereal fn)
so that if class X could receive both [](){}
and [](int){}
.