Conditional configuration of a C++ module

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
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.
Topic archived. No new replies allowed.