4 ms·
How can we replace nested comments? You can't comment out code that contains /* */ in it except with #if 0 Also, why is std::experimental::source_location loc
by Aardwolf 6y ago
How can we replace nested comments? You can't comment out code that contains /* */ in it except with #if 0
Also, why is std::experimental::source_location loc = std::experimental::source_location::current(); loc.line better than __LINE__? what an unreadable monster that is!
- layer8 6y ago> How can we replace nested comments? s/^/\/\// (and the reverse) work well for me. It nests.
- eugene3306 6y ago> How can we replace nested comments? you may use multiline string literals
- tkln 6y agoCare to elaborate on how that's supposed work in practice?
- MauranKilom 6y agoPresumably it would become auto loc = std::source_location::current(); at some point, which seems fair enough to me.
- unglaublich 6y agoIt is since C++20. Comment author tries to make code verbose to make their point or does not know about auto and the state of C++.
- Aardwolf 6y agoI simply copied it from the article (minus the surrounding function). Fortunately you only need to write this at the utility function, not at every call site, so it's ok. In general I find various new features in C++ suffer from verbosity, but of course without experimental this one gets better.
- identity0 6y agoauto in function signatures is just really, really stupid.
- jpz 6y agoI mean, don't love the macros - but that still looks like a load of typing to me - and it even reads less well than __LINE__ if you are looking at from a literate programming perspective. It's tidier for the compiler though, but the change does not seem to make it easier for the reader of the code to comprehend.
- deleted 6y ago[deleted]
- mhh__ 6y agoThe idea is to get the location of the caller without using a macro. D just uses __LINE__, because it hasn't got a preprocessor so the compiler can resolve the token properly. The implementation of that is at https://github.com/dlang/dmd/blob/v2.094.2/src/dmd/expression.d#L6782 https://github.com/dlang/dmd/blob/v2.094.2/src/dmd/expressio...
- deleted 6y ago[deleted]
- sesuximo 6y agoSource location is so much more than that macro!! - it has file name, line number, and char number! That already makes the number of characters more similar if that’s your metric - it can be forwarded/passed around. It’s much harder to pass macros around - it can easily capture the caller’s location rather than the location of the macro
- PaulDavisThe1st 6y agoSince #define will still exist, I'd suggest #define __WHERE__ std::source_location::current() :)