I am using an application in c++ that uses a special dprintf function to print information, this is an example:
dprintf(verbose, 'The value is: %d', i);
What is doing is when I define verbose for test purposes then I print the information and when I am working in normal execution I do not define it and I do not see useless information in the screen. My question is how can I do that function or implement the same idea?.
I try to avoid using var-arg c-style functions for two main reasons:
I’ve made a way that works using
boost::fusion, which is given arguments in a type-safe way. It iterates over those arguments, printing out them when a%is encountered. If too few or too many arguments were given, an exception is thrown.There is one problem still: Variadic macros are not yet standard in C++. So, i have made two versions. One that work with current C++. You have to invoke it using
Then. The other version, using variadic macros, can be used by defining a preprocessor symbol, which enables you to write
Here is the code. The
boost.fusionprovides more details for this: