Earlier quoted context omitted.
This is the reason yes, and why macro encapsulation by modules is so important
How do modules work with generics and cross-module inline functions? Probably I can find the answer in D or Rust but I am not familiar with their mechanisms. Thanks.
Is the preprocessor still needed in C++? (2017)
61–65 of 65 posts
Re: Is the preprocessor still needed in C++? (2017)
#62Earlier quoted context omitted.
Isn’t that what templates and constexpr are?
To a degree, but templates and constexpr don't support a bunch of features like compile-time field enumeration and introspection + code generation. For example, let's say I have a bunch of structs: struct GeoCoordinate { int lat, long; }; struct GeoArea { std::vector perimeter; }; struct Place { std::string name; std::string contact_number; GeoArea area; }; Now I need to serialize these structs into a format to be se…
Re: Is the preprocessor still needed in C++? (2017)
#63Missing the most important case: Some external library you need changes a function signature and you need to be able to compile against the old or the new library, eg: #if LIBVERSION >= 2 draw_point (2, 3, RED); #else set_color (RED); draw_point (2, 3); #endif This is actually a case where the C preprocessor would be useful in many more languages. OCaml has cppo which is like a better cpp and is very useful for solvi…
Re: Is the preprocessor still needed in C++? (2017)
#64Earlier quoted context omitted.
You can use "if constexpr" for that.
In this case this doesn't work because "if constexpr" parses both branches. If the new library version changes function signatures, the if-branch for the old library version produces an error: https://www.godbolt.org/z/4KK997 PS: interesting to note that Zig does the "right thing": https://www.godbolt.org/z/9c13PY
Andrei Alexandrescu mentions it in a talk, if constexpr doesn't really do much of anything useful because it introduces a scope.
Re: Is the preprocessor still needed in C++? (2017)
#65The best thing about C++ preprocessor is that it is dumb. Text goes in, text goes out. Easy to debug, simple rules. Anything I saw as an alternative either requires a significant amount of code, bending C++ rules, or specialized tools to see what is going on. Java tried so hard to "do the right thing" by abolishing the preprocessor, and we ended up with another preprocessor called IDE, unnecessary code patterns, and…