可變參數模板假設我有一類具有一定數量的方法:處理方法,結果
class Foo {
bool someMethodA(int someParamA, double someParamB, int someParamC);
bool someMethodB(double someParamA);
bool someMethodC(double someParamA);
...
}
每種方法都有不同的簽名。有沒有一種方便的方法來調用這些方法,以便在true(成功)上調用通告程序方法?
notifySuccess();
宏來做到這一點:
// Call a function notifyAll() on success
#define NOTIFY_ON_SUCCESS(func) \
bool success = func; \
if (success) { \
notifySuccess(); \
} \
return success;
它被認爲有辦法做到這一點使用可變參數模板呢?喜歡的東西:
template <typename... ARGS>
bool CallImplAndNotify(bool (&SceneImpl::*func)(ARGS...), ARGS... args) {
bool result = func(args...);
...
}