@@ -654,20 +654,21 @@ class DebugOutput {
654654 }
655655
656656 template <typename ... T>
657- auto print (std::initializer_list<expr_t > exprs, T&&... values)
658- -> last_t<T...> {
657+ auto print (std::initializer_list<expr_t > exprs,
658+ std::initializer_list<std::string> types,
659+ T&&... values) -> last_t<T...> {
659660 if (exprs.size () != sizeof ...(values)) {
660661 std::cerr
661662 << m_location << ansi (ANSI_WARN)
662663 << " The number of arguments mismatch, please check unprotected comma"
663664 << ansi (ANSI_RESET) << std::endl;
664665 }
665- return print_impl (exprs.begin (), std::forward<T>(values)...);
666+ return print_impl (exprs.begin (), types. begin (), std::forward<T>(values)...);
666667 }
667668
668669 private:
669670 template <typename T>
670- T&& print_impl(const expr_t * expr, T&& value) {
671+ T&& print_impl(const expr_t * expr, const std::string* type, T&& value) {
671672 const T& ref = value;
672673 std::stringstream stream_value;
673674 const bool print_expr_and_type = pretty_print (stream_value, ref);
@@ -679,8 +680,7 @@ class DebugOutput {
679680 }
680681 output << ansi (ANSI_VALUE) << stream_value.str () << ansi (ANSI_RESET);
681682 if (print_expr_and_type) {
682- output << " (" << ansi (ANSI_TYPE) << type_name<T>() << ansi (ANSI_RESET)
683- << " )" ;
683+ output << " (" << ansi (ANSI_TYPE) << *type << ansi (ANSI_RESET) << " )" ;
684684 }
685685 output << std::endl;
686686 std::cerr << output.str ();
@@ -689,10 +689,12 @@ class DebugOutput {
689689 }
690690
691691 template <typename T, typename ... U>
692- auto print_impl (const expr_t * exprs, T&& value, U&&... rest)
693- -> last_t<T, U...> {
694- print_impl (exprs, std::forward<T>(value));
695- return print_impl (exprs + 1 , std::forward<U>(rest)...);
692+ auto print_impl (const expr_t * exprs,
693+ const std::string* types,
694+ T&& value,
695+ U&&... rest) -> last_t<T, U...> {
696+ print_impl (exprs, types, std::forward<T>(value));
697+ return print_impl (exprs + 1 , types + 1 , std::forward<U>(rest)...);
696698 }
697699
698700 const char * ansi (const char * code) const {
@@ -785,9 +787,12 @@ auto identity(T&&, U&&... u) -> last_t<U...> {
785787#define DBG_STRINGIFY_IMPL (x ) #x
786788#define DBG_STRINGIFY (x ) DBG_STRINGIFY_IMPL(x)
787789
788- #define dbg (...) \
789- dbg::DebugOutput (__FILE__, __LINE__, __func__) \
790- .print({DBG_MAP (DBG_STRINGIFY, __VA_ARGS__)}, __VA_ARGS__)
790+ #define DBG_TYPE_NAME (x ) dbg::type_name<decltype (x)>()
791+
792+ #define dbg (...) \
793+ dbg::DebugOutput (__FILE__, __LINE__, __func__) \
794+ .print({DBG_MAP (DBG_STRINGIFY, __VA_ARGS__)}, \
795+ {DBG_MAP (DBG_TYPE_NAME, __VA_ARGS__)}, __VA_ARGS__)
791796#else
792797#define dbg (...) dbg::identity(__VA_ARGS__)
793798#endif // DBG_MACRO_DISABLE
0 commit comments