Is the preprocessor still needed in C++? (2017)
foonathan.net
Is the preprocessor still needed in C++? (2017)
1–10 of 65 posts
Re: Is the preprocessor still needed in C++? (2017)
#2Also, why is std::experimental::source_location loc = std::experimental::source_location::current(); loc.line better than __LINE__? what an unreadable monster that is!
Re: Is the preprocessor still needed in C++? (2017)
#3"With current C++(17), most of the preprocessor use can’t be replaced easily."
"And even then: I think that proper macros, which are part of the compiler and very powerful tools for AST generation, are a useful thing to have. Something like Herb Sutter’s metaclasses, for example. However, I definitely don’t want the primitive text replacement of #define."
Re: Is the preprocessor still needed in C++? (2017)
#4How 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!
s/^/\/\// (and the reverse) work well for me. It nests.
Re: Is the preprocessor still needed in C++? (2017)
#5How 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!
you may use multiline string literals
Re: Is the preprocessor still needed in C++? (2017)
#6How 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!
auto loc = std::source_location::current();
at some point, which seems fair enough to me.Re: Is the preprocessor still needed in C++? (2017)
#7Something akin to the https://www.python.org/dev/peps/pep-0638/
Code generators/transformers are rare only because it's so hard to actually start.
Too bad https://www.circle-lang.org never took off.
Re: Is the preprocessor still needed in C++? (2017)
#8 #define MEMBER(C, M) { offsetof(C, M), sizeof(C::M) }
I couldn't figure out nice a way to do this without the preprocessor. The best I came up with was to use a lambda: [] (const C& c) { return std::cref(c.m); }
But these are stored in a std::map which means I have to use function pointers or accept the overhead of std::functionRe: Is the preprocessor still needed in C++? (2017)
#9Every single "fix" probably requires more lines of code under the hood than the entire preprocessor and in the end you have added tons of additional features to the language to fix problems that (often) don't need fixing.
The preprocessor being a simple text replacement tool is a feature, not a bug, but like every universal tool it requires some common sense to not abuse it.
Re: Is the preprocessor still needed in C++? (2017)
#10We just need an interpreter that can work on C++ files, supported by the standard. Something akin to the https://www.python.org/dev/peps/pep-0638/ Code generators/transformers are rare only because it's so hard to actually start. Too bad https://www.circle-lang.org never took off.