Show HN: A C++ dump func. that can print multi-D vectors, maps, tuples, and all
github.com
github.com
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)
https://github.com/philip82148/cpp-dump/blob/main/hpp/export...
Is there a reason not to just handle/accept everything that has a valid `std::tuple_size` specialization?
BTW, actually I made this for competitive programming. The reason the library has some macros is also the macros are useful for competitive programming. And I thought it might be useful also for debugging productions, so I created this post.
I am learning a lot from everyone's advice. New advice is welcome, too. (I don't want harsh advice, though. :smile:)
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).To philip82148, don't let the critics pull you down, you made it to the front page after and they probably haven't. You can still learn from them (your use of a goto when a while would have been probably sufficient) but ignore the negativity.
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.
I'm advising you to reflect on your words on how they do or don't add professional value.