sharkdp / dbg-macro

A dbg(…) macro for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How about output "{?}" string for unknown types instead of failing with static assert?

YarikTH opened this issue · comments

I trying to debug highly templated code. And some of the debugged values have ostream overloads, some don't have. The library force to write ostream overloads for every type or it give up to compile. I suggest altering pretty_print false_type to output some fake but recognizable value like doctest does.

template <typename T>
inline void pretty_print(std::ostream& stream, const T&, std::false_type) {
  stream << "{?}";
}

This allows using the library more convenient way and the user has pretty type information anyway even they don't have the value printed. And if user do want to see the value, they have to support ostream operator anyway.

Thank you for your feedback.

I'm not sure that's the best thing to do. In which scenario would it be useful to get the {?} output? Wouldn't the user rather like to see a compile error to know that a ostream operator is missing?

If you are only interested in type information, you can always use dbg::type<T>(). Admittedly, it's a bit more verbose if you want to print the type of an expression:

dbg(dbg::type<decltype(expr)>());

Maybe we could try to make that a bit easier? For example, by introducing:

#define dbg_type(expr) dbg(dbg::type<decltype(expr)>())

I'm not sure about this. It can be either my use-case where I don't have ostream operators for most of the types yet or my personal taste. I can make this change in one line any time anyway in my copy.