How to wrap a function with variable length arguments?

后端 未结 7 2062
借酒劲吻你
借酒劲吻你 2020-12-05 12:54

I am looking to do this in C/C++.

I came across Variable Length Arguments but this suggests a solution with Python & C using libffi.

Now, if I want to wr

7条回答
  •  没有蜡笔的小新
    2020-12-05 13:14

    In C++11 this is one possible solution using Variadic templates:

    template
    void myprintf(const char* fmt, Args... args )
    {
        std::printf( fmt, args... ) ;
    }
    

    EDIT

    As @rubenvb points out there are trade-offs to consider, for example you will be generating code for each instance which will lead to code bloat.

提交回复
热议问题