I don’t know if this can be achieved through variadic template, variadic marcos or even maybe metaprogramming.
Basically I have a logging object like this:
LOG << "This is the value of variable X: " << varaibleX;
but I also want this to be able to use LOG like a function
LOG ( "This is the value of variable X: ", variableX);
but the number of argument can be varying. (assuming they call can be converted into streams)
I was looking at LOG ( ... ), but really not sure how to expand the arguments.
So let’s say someone wrote
LOG(X, Y, Z);
and I want to expand this into:
LOG << X << Y << Z;
Can this be done?
This can be done with variadic templates like below. Since its not clear what your LOG object is, I omitted the code to actually call LOG(…), but you should be able to port this do what you need:
You’ll need to compile this with c++0x support. With g++, this can be done using the –std=c++0x flag.