Wrap a function pointer in C++ with variadic template

后端 未结 3 1876
借酒劲吻你
借酒劲吻你 2020-12-15 07:58

The Question

I have a number of C++ functions void f(), R g(T a), S h(U a, V b) and so on. I want to write a template functi

3条回答
  •  無奈伤痛
    2020-12-15 08:29

    template
    typename std::result_of::type
    wrapper(Args&&... args) {
        return fn(std::forward(args)...);
    }
    #define WRAPPER(FUNC) wrapper
    

    //Usage:

    int min(int a, int b){
        return (a
    #include
    int main(){
        std::cout<

    Alternatively, to get maybe quite less readable, but shorter syntax:

    #define WRAPPER(FUNC, ...) wrapper(__VA_ARGS__)
    

    //Usage:

    int main(){
        sdt::cout<

提交回复
热议问题