C++11 variable number of arguments, same specific type

A possible solution is to make the parameter type a container that can be initialized by a brace initializer list, such as std::initializer_list<int> or std::vector<int>. For example: #include <iostream> #include <initializer_list> void func(std::initializer_list<int> a_args) { for (auto i: a_args) std::cout << i << ‘\n’; } int main() { func({4, 7}); func({4, 7, 12, 14}); }

Passing parameters dynamically to variadic functions

Variadic functions use a calling convention where the caller is responsible for popping the function parameters from the stack, so yes, it is possible to do this dynamically. It’s not standardized in C, and normally would require some assembly to manually push the desired parameters, and invoke the variadic function correctly. The cdecl calling convention … Read more

Is there a way to use C++ preprocessor stringification on variadic macro arguments?

You can use various recursive macro techniques to do things with variadic macros. For example, you can define a NUM_ARGS macro that counts the number of arguments to a variadic macro: #define _NUM_ARGS(X100, X99, X98, X97, X96, X95, X94, X93, X92, X91, X90, X89, X88, X87, X86, X85, X84, X83, X82, X81, X80, X79, X78, … Read more

Objective-C passing around … nil terminated argument lists

You can’t do this, at least not in the way you’re wanting to do it. What you want to do (pass on the variable arguments) requires having an initializer on UIAlertView that accepts a va_list. There isn’t one. However, you can use the addButtonWithTitle: method: + (void)showWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, … Read more

Forward an invocation of a variadic function in C

Not directly, however it is common (and you will find almost universally the case in the standard library) for variadic functions to come in pairs with a varargs style alternative function. e.g. printf/vprintf The v… functions take a va_list parameter, the implementation of which is often done with compiler specific ‘macro magic’, but you are … Read more

How to use R’s ellipsis feature when writing your own function?

I read answers and comments and I see that few things weren’t mentioned: data.frame uses list(…) version. Fragment of the code: object <- as.list(substitute(list(…)))[-1L] mrn <- is.null(row.names) x <- list(…) object is used to do some magic with column names, but x is used to create final data.frame. For use of unevaluated … argument look … Read more

tech