Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds empty dbg calls #67

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ int main() {

dbg("this line is executed"); // [example.cpp:23 (main)] this line is executed

dbg(); //[example.cpp:28 (main)] dbg call reached.

factorial(4);

return 0;
Expand Down
25 changes: 23 additions & 2 deletions dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,35 @@ T&& identity(T&& t) {

} // namespace dbg

// Intermediate macro "chooser"
#define dbg_x(x, A, Func, ...) Func

// Macro to be called and used by user
// First param must be blank to allow for 0 argument function
#define dbg(...) dbg_x(, ##__VA_ARGS__, dbg_VA(__VA_ARGS__), dbg_0())

#ifndef DBG_MACRO_DISABLE

// Empty macro, prints "dbg call reached."
#define dbg_0() \
dbg::DebugOutput(__FILE__, __LINE__, __func__, "") \
.print(dbg::type_name<decltype("")>(), ("dbg call reached."))

// The normal macro, prints expression and type
// We use a variadic macro to support commas inside expressions (e.g.
// initializer lists):
#define dbg(...) \
#define dbg_VA(...) \
dbg::DebugOutput(__FILE__, __LINE__, __func__, #__VA_ARGS__) \
.print(dbg::type_name<decltype(__VA_ARGS__)>(), (__VA_ARGS__))

#else
#define dbg(...) dbg::identity(__VA_ARGS__)

// Empty macro
#define dbg_0()

// Normal macro, passes value through
#define dbg_VA(...) dbg::identity(__VA_ARGS__)

#endif // DBG_MACRO_DISABLE

#endif // DBG_MACRO_DBG_H
2 changes: 2 additions & 0 deletions tests/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ int main() {
dbg("this line is executed"); // [example.cpp:23 (main)] this line is
// executed

dbg(); //[example.cpp:28 (main)] dbg call reached.

factorial(4);

return 0;
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ int main() {
dbg(test_c_chararray);
dbg(test_string);

dbg("====== empty calls");

dbg();

dbg("====== r-values, literals, constants, etc.");

dbg(42);
Expand Down