Dec 7, 2021 at 4:23pm
Hi,
I am looking for ways to configure a C++ 20 Module. For instance:
in ordinary (pre C++ 20) code I have this conditional compilation:
1 2 3 4 5
|
#if CONDITION == 1
void do_something();
#else
void do_something_else();
#endif
|
If this conditional code is in a .ixx file (module interface file), how can I configure it?
Since I cannot use macros that are visible in the module, I thought I'd use a :
1 2 3 4 5 6 7
|
export constinit int configuration = 1;
#if configuration == 1
void do_something();
#else
void do_something_else();
#endif
|
]
This does not seem to work either because preprocessor occurs before compilation.
Any ideas?
Regards,
Juan
Last edited on Dec 7, 2021 at 4:24pm
Dec 8, 2021 at 9:09am
It depends on what you are trying to achieve with this condition.
Normally I would say: Put the conditional code each in its own file. Depending on what you want to do include the one or other in your project.