My application uses another output than the standard output for logging information, which is why I wrote my own Log(), Error(), Panic() and Assert() functions. To organize things nicely, I enclose all the debugging stuff in a Debug namespace.
It would make more sense for the Assert() function to also provide a source file and line number, which is only possible using the __LINE__ and __FILE__ macros. However, it is pretty unpleasant, inefficient etc... to always have to specify these two parameters.
So this is how my code would look like:
namespace Debug { void Assert (int condition, std::string message, std::string file, int line); } My question is, is it possible to place a macro which includes those two parameters inside the Debug namespace? Like this:
namespace Debug { void Assert_ (int condition, std::string message, std::string file, int line); #define Assert(a,b) Assert_(a, b, __FILE__, __LINE__) } // .... Somewhere where I call the function .... Debug::Assert (some_condition, "Some_condition should be true"); // Output: Assertion failed on line 10 in file test.cpp: // Some_condition should be true Is this valid c++? If not, is there any way of making this work?
Debug::, the macro would still work?AsserttoAssert_in the preprocessor) - the problem is that if you useAssertoutside the namespace then it will still get translated, which is probably not be what you want to happen.