Skip to content

Commit

Permalink
Added empty dbg calls, closes #64
Browse files Browse the repository at this point in the history
dbg can now be called like dbg() with no arguments. Works by using the
VA_ARGS to determine how many arguements have been passed in via dbg_x.
Also works just fine if DBG_MACRO_DISABLE is defined.
  • Loading branch information
DerekCresswell committed Dec 17, 2019
1 parent c742469 commit d2c7f62
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,39 @@ T&& identity(T&& t) {

} // namespace dbg_macro

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

#ifndef DBG_MACRO_DISABLE

// Empty macro, prints "dbg call reached."
#define dbg_0() \
dbg_macro::DebugOutput(__FILE__, __LINE__, __func__, "") \
.print(dbg_macro::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_macro::DebugOutput(__FILE__, __LINE__, __func__, #__VA_ARGS__) \
.print(dbg_macro::type_name<decltype(__VA_ARGS__)>(), (__VA_ARGS__))

// 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())

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

// Empty macro
#define dbg_0()

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

// Macro called by user
// First param must be blank
#define dbg(...) dbg_x(, ##__VA_ARGS__, dbg_VA(__VA_ARGS__), dbg_0())

#endif // DBG_MACRO_DISABLE

#endif // DBG_MACRO_DBG_H

0 comments on commit d2c7f62

Please sign in to comment.