Is it possible to write a macro which can take in a variable number of arguments and expands like this :
quickdebug(a) -> cout << #a ": " << a;
quickdebug(a,b) -> cout << #a ": " << a << #b ": "<< b;
etc
If not, is it possible for me to at least print all the arguments without giving format strings. e.g
quickdebug2(a) -> cout << a ;
quickdebug2(a,b) -> cout << a << " " << b ;
etc
For example in java I can write a function which provides me similar functionality:
void debug(Object...args)
{
System.out.println(Arrays.deepToString(args));
}
#a. So the analogy is incorrect. You can accomplish what you did in Java with variadic templates in C++ (or multiple non variadic templates).printfvariadic template in Wikipedia. Your version would go something like this:void quickdebug() { } template<typename A, typename... B> void quickdebug(A a, B... b) { std::cout << a; quickdebug(b...); }