Groovy convert from List to var args for method call

Probably the spread operator, *, is what you’re looking for: def to(String… emails) { emails.each { println “Sending email to: $it”} } def emails = [“t@a.com”, “t@b.com”, “t@c.com”] to(*emails) // Output: // Sending email to: t@a.com // Sending email to: t@b.com // Sending email to: t@c.com Notice that the parentheses on the method call to … Read more

Does printf(“%x”,1) invoke undefined behavior?

I believe it is technically undefined, because the “correct type” for %x is specified as unsigned int – and as you point out, there is no exception for signed/unsigned mismatch here. The rules for printf are for a more specific case and thus override the rules for the general case (for another example of the … Read more

Java generics and varargs

As almost always, Angelika Langer’s Java generics FAQ explains it in great detail. (Scroll to “Why does the compiler sometimes issue an unchecked warning when I invoke a “varargs” method?” – the ID doesn’t work well.) Basically, you end up losing information in a worse way than normal. Yet another little pain point in Java … Read more

trailing return type using decltype with a variadic template function

I think the problem is that the variadic function template is only considered declared after you specified its return type so that sum in decltype can never refer to the variadic function template itself. But I’m not sure whether this is a GCC bug or C++0x simply doesn’t allow this. My guess is that C++0x … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)