I have the following:
struct Args;
template <typename T>
void DoStuff(T&& callback) {
// ... do stuff
MyArgs args = ...
callback(args);
}
Which is great, I can do the following:
void callback(const Args &);
DoStuff(callback);
And:
DoStuff([](const Args &) { ... });
And:
class CallbackClass {
operator()(const Args &);
};
CallbackClass myCallbackClass;
DoStuff(myCallbackClass);
All is nice and good, now I want to do two improvements here:
Enforce that the signature of
Tis alwaysvoid(const Args &)because in the current state of things I can do the following:void badCallback(Args); DoStuff(badCallback);Allow (in addition to the previous options) to pass an object with an specific named member function that would also be allowed to be a callback, example:
class NamedCallback { void PerformCallback(const Args &); }; NamedCallback myNamedCallback; DoStuff(myNamedCallback);
Is it possible?