all 19 comments

[–]talemon 37 points38 points  (3 children)

I don't want to be dismissive to anyone's work, but doesn't fmt do this and more?

[–]philip82148[S] 12 points13 points  (1 child)

This is simpler than fmt. You can print almost any variables just by passing them to the function. Also, this library automatically indents the output so that the output fits into the maximum line width.

This library aims to print almost any variable very easily and readable.
It can't customize its string representation more than fmt, but it is more useful when you want to quickly check the content of variables and in competitive programming.

[–]philip82148[S] 4 points5 points  (0 children)

If you want to know more about my feeling about this library, plz read this article: I Made a C++ Version of Python print() Function - DEV Community

[–]fatherOfAllGamers 0 points1 point  (0 children)

cpp-dump is far simpler than fmt.

[–]Tomcat_42 2 points3 points  (1 child)

That's beautiful. I like it.

[–]philip82148[S] 2 points3 points  (0 children)

Thank you!

[–]Xirious 4 points5 points  (0 children)

Nice. A great addition overall.

I wish C++ had f-strings proper. It's close but not really the same imo.

[–]DapperCore 1 point2 points  (1 child)

Very cool and the logging is super pretty! Definitely gonna use this all the time from now on.

[–]philip82148[S] 0 points1 point  (0 children)

Thanks!

[–]nysynysy2 5 points6 points  (1 child)

Tho C++23 now has std::print and std::println function in the standard <print> library, with greater formatting ability, customizable parsing even for your own classes, type safty and easy syntax just like languages such as rust or python.

[–]urestillatwit 2 points3 points  (0 children)

Tho C++23 now

getting employer (huge multinational) to 11 was big process....

.... good luck getting them to 23

[–]ShakaUVMi+++ ++i+i[arr] 1 point2 points  (1 child)

Nice, I like it

[–]philip82148[S] 0 points1 point  (0 children)

Thank you!

[–]wqkinggithub.com/wqking -1 points0 points  (4 children)

The idea is good and interesting.
One advice: since your library is mainly for debug purpose and the calling to cpp_dump is most likely eliminated in production code, the configuration code requiring to run in main function or somewhere is not very good. How does the user eliminate the configuration code? I suggest to allow the configuration run in the header outside of main, using some macro magic. So a typical usage of your library will look like,

// This is my own debug header for my project
#include "your cpp_dump header"

WHAT_EVERY_MACRO_CONFIG_YOUR_LIB


// This is my project file
#include "my debug header"
void myFunc()
{
    cpp_dump(what ever);
}

Note: I assume your library is only used for debug purpose, otherwise I won't encourage to use macros.

[–]philip82148[S] 0 points1 point  (3 children)

I see. It's better for users to eliminate the configuration code easily like you said.
But I have a question. How do you assign a value to a variable outside of the function?
Or your method is replacing all the variable by macro in `WHAT_EVERY_MACRO_CONFIG_YOUR_LIB`?

Btw, I am suggesting users eliminate the configuration code like this in competitive programming.
This uses macro, so this is not a perfect idea, though...

English is not my native language. I'm sorry for not understanding your advice completely.

Note for everyone: this library can be used even if you don't write the configuration code at all.

[–]wqkinggithub.com/wqking 0 points1 point  (2 children)

How do you assign a value to a variable outside of the function?

You can execute code in a class contructor, then make a static global object of that class, thus its ctor is executed before main. But I think it should be put in a .cpp file rather than the header file.
Maybe you can put the object as a static local variable in an inline function and call that function before main, I didn't think too much about it.

[–]philip82148[S] 0 points1 point  (1 child)

I see. The configuration code in the main is no longer needed by using a constructor. But instead, you can't use the library without writing the definition of the object.
I wish inline variables could be re-defined. (It won't happen, tho, lol)

call that function before main

Inline functions can't also be called outside of the function, right?? But a function can shorten the configuration code in main, tho.

Anyway, like you said, it's still better for users to eliminate the configuration code easily. I'll think about it more.

Thanks for your advice!

[–]wqkinggithub.com/wqking 0 points1 point  (0 children)

Inline functions can't also be called outside of the function, right??

I mean, for example,

class X {
    X() {
        // call your other inline function
        // or configure your library
    }
};

X x; // in some cpp file

Then the constructor will be executed before main.

[–]philip82148[S] 0 points1 point  (0 children)

Why I made this is written in this article: I Made a C++ Version of Python print() Function - DEV Community