Why use variadic arguments now when initializer lists are available?

If by variadic arguments you mean the ellipses (as in void foo(…)), then those are made more or less obsolete by variadic templates rather than by initializer lists – there still could be some use cases for the ellipses when working with SFINAE to implement (for instance) type traits, or for C compatibility, but I …

Read more

How to reverse the order of arguments of a variadic template function?

Overall approach and usage The overal approach consists in packing the arguments into an std::tuple of references, exploiting the perfect forwarding machinery of std::forward_as_tuple(). This means that, at run-time, you should incur in very small overhead and no unnecessary copy/move operations. Also, the framework does not use recursion (apart from compile-time recursion, which is unavoidable …

Read more

How do you call an Objective-C variadic method from Swift?

Write a va_list version of your variadic method; + (NSError *)executeUpdateQuery:(NSString *)query, … { va_list argp; va_start(argp, query); NSError *error = [MyClassName executeUpdateQuery: query args:argp]; va_end(argp); return error; } + (NSError *)executeUpdateQuery:(NSString *)query args:(va_list)args { NSLogv(query,args); return nil; } This can then be called from Swift MyClassName.executeUpdateQuery(“query %d, %d %d”, args: getVaList([1,2,3,4])) Add an extension …

Read more

Why does printf() promote a float to a double?

Yes, float arguments to variadic function are promoted to double. The draft C99 standard section 6.5.2.2 Function calls says: […]and arguments that have type float are promoted to double. These are called the default argument promotions.[…] from the draft C++ standard section 5.2.2 Function call: […]a floating point type that is subject to the floating …

Read more