Comments (8)
I didn't know that we could use dbg
as a namespace name in addition to the macro name. Neat!
I started an initial implementation here: #68
Glad for any feedback.
from dbg-macro.
Implementation idea:
dbg(dbg_hex(number))
dbg_hex
is a simple templated struct which hold the value. std::ostream& operator<<
would be specialized to print as hex like you shown in the README.
from dbg-macro.
Thank you for your feedback!
I see how this could be useful and I kind of like the idea. The issue I see is that this could lead to feature creep.
For now, this header has a very simple "API": the dbg(β¦)
macro - nothing more. If we decide to add custom formatting options, I'm afraid it would lead to a whole bunch of things that could potentially be added.
Also, I would like to avoid adding more names to the global namespace. If at all, it should probably be dbg(dbg_macro::hex(β¦))
. If this could somehow nicely integrate with the I/O manipulators from <ios>
and <iomanip>
, that would be an option. But I don't want dbg(β¦)
to take a second optional argument (see #2).
from dbg-macro.
I agree to not polluting the global namespace. But to keep consistency, maybe we should also move the dbg(...)
macro to that new namespace? Or name the namespace dbg
!
There are lots of flag from <ios>
header. Best case would be supporting all of them.
When debugging, we want to be fast. No time to write a complex line like std::cout << std::hex << value << std::endl
. Especially if we have more than one value to print (dbg()
already solve this problem).
One problem is that std::ostream
(cout
, cerr
and more) save flags that were set.
std::cout << std::hex;
std::cout << 15 << std::endl;
This code effectively print f
(https://godbolt.org/z/caMvrD). If we apply flags from <ios>
we have to duplicate std::cerr
to not break user-defined flags (std::ostream stream(std::cerr.rdbuf())
). Example: https://godbolt.org/z/J0GnAr
I suppose that debugging is consistent enough on a project lifetime so we can do the following (it is not a naming proposition):
dbg::set(std::hex);
dbg::set(std::boolalpha);
...
dbg(true);
dbg(15);
We keep the fast use of dbg()
for all values, with an added optional set()
, which could be project-scoped (example: set at top of the main()).
from dbg-macro.
Congrats!
I'll take a deep look in a day or two. Promise I'll feedback!
from dbg-macro.
I didn't know that we could use
dbg
as a namespace name in addition to the macro name. Neat!
A macro is a preprocessor! That mean it gets translated in pre-processing which happen before compilation π
from dbg-macro.
A macro is a preprocessor! That mean it gets translated in pre-processing which happen before compilation yum
I was afraid that the preprocessor (because it does not know anything about the syntax) would maybe affect a string like namespace dbg {
when a #define dbg(β¦) β¦
was around.
from dbg-macro.
I left a review! Great work :)
from dbg-macro.
Related Issues (20)
- Windows Supported? HOT 14
- Broken output of containers HOT 6
- How about output "{?}" string for unknown types instead of failing with static assert? HOT 2
- Allow specifying the output stream HOT 9
- Is support it for android ? HOT 2
- Is it possible to allow variadic template expansion? HOT 8
- VS2015οΌerror C2912 HOT 5
- debug print on some condition HOT 3
- use in Qt HOT 1
- Add output level HOT 2
- `Type does not support the << ostream operator` on custom type HOT 10
- multithread support HOT 1
- Support always on colors HOT 2
- Nested dbg(...) expansion as not expected HOT 2
- How to force print the full content, not the one with ellipsis HOT 3
- Support for container adapters HOT 1
- Fails with Eigen matrices HOT 7
- Suggest /usr/local/include instead of /usr/include HOT 3
- Report a compiling error with old GCC version (GCC 4.8.5) HOT 1
- Some enhancement proposals for CMake based usecases HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbg-macro.