Conditional compiling to be replaced by metaprogramming constructs? #2063
Replies: 3 comments 10 replies
-
I completely agree. And |
Beta Was this translation helpful? Give feedback.
-
Another good question is, without the preprocessor, what would be the most convenient data structure to pass the compile-time constants with the default definitions (similar to the preprocessor default macros) back to the compiled source? With the preprocessor, it is very convenient to use |
Beta Was this translation helpful? Give feedback.
-
I think there are several issues with using compile-time expressions instead of preprocessor commands to enable/disable code:
|
Beta Was this translation helpful? Give feedback.
-
This is a follow up of #2052, but addressing a different topic.
With metaprogramming expected to replace the preprocessor, I'm trying to figure out how current C++ code would have to be changed to no longer use the preprocessor conditional compiling syntax.
Conditional compiling examples
For this I collected some snippets from my projects (comments removed to reduce clutter):
Conditional include header
Conditional compile function content
Conditional compile type content
Similar cases can be imagined for struct/class content.
Conditional compile array content
Conditional function declarations
Similar cases can be imagined for function definitions.
Comments
Apart from the second example (function content) where I can imagine some
if constexpr ()
statement (fictive syntax!) to replace the functionality of the preprocessor, for the other examples I have some difficulties to imagine how the metaprogramming syntax would look like. :-(It seems like we'll need to accept some form of
if constexpr ()
statements both outside any scope (at file scope) and in unusual places, like inside type definitions.I don't imply that such a syntax is wrong or impossible, I just confess that I have no experience with other languages able to do this, and I would expect that designing such a metaprogramming syntax will require some inovative ideas and a lot of thinking.
If someone more knowledgeable has experience with such languages and can share it, or suggest possible syntax that will have similar functionality as the previous preprocessor examples, please contribute to this thread.
Beta Was this translation helpful? Give feedback.
All reactions