39 points by philip82148 9 hours ago | | 9 comments

I've been using something similar lately for my "quick and dirty print debugging" needs [1]. It's much nicer and requires less effort than just using printf/cout. I feel like many of the critical comments here are missing that that's probably the intended use-case of this.

[1] https://github.com/sharkdp/dbg-macro

reply

Didn't check whether it hardcodes support for std::pair and std::tuple, but the "correct" way to do this is to rely on `std::tuple_size` and `std::tuple_element` for all tuple-like types. User types may well have these customizations defined already for e.g. structured binding support.

reply

Mmm, hard-coding std::clog, using std::endl, not professional-grade stuff.

reply

Im not sure why exsctly you would prefer this over just a few overloads of "operator<<"?

Why is it all macros? That seems ancient. Again, you could do this more cleanly with concepts and a templated operator<<, which then also supports more than just std::clog (fmt/std::format will happily use operator<< for example)

reply

It’s macros because it dumps the expression. There is a non macro variant.

Most of these libraries are in my opinion quite misguided.

What you want when dumping/logging is a structured machine readable output. You just want to provide an API where you can define how any type is structured. Then use that information to emit any format you want (JSON, BSON, CSV, arrow, whatever).

From that you can then build your pretty printer in any way you want the data to be printed.

reply

fmt already supports containers. Does it not support nested ones? The docs aren't clear.

Even if not, this library would surely be best implemented in terms of fmt. You could define a utility class "dump" that just holds a reference to the object you want to format. Then you can use it like this:

    fmt:: print("{}", dump(foo));
Then define a formatter for dump that uses constexpr if to decide whether to format the underlying object directly or to use your custom iteration logic. That is more extensible (it can format anything that fmt can), it avoids macros, and it's more efficient (it can format directly into the target buffer).
reply

There's also

    goto rollback
Surely you could have avoided this with a bit of refactoring, probably by splitting the monolithic formatting function for containers into more manageable chunks.

This is a fun learning project, not a production worthy library worth posting on HN.