Before delving into a project, I just want to make certain my understanding is correct as I haven't played with this before.
If I create a cross-platform program, the standard way to have the platform-specific code is to put it in a
.h / .cpp file combo and
#include
it based on a header definition:
#ifdef WINDOWS
#include "WindowsSpecificXXX.h"
#elseif APPLE
#include "AppleSpecificXXX.h"
...
#endif
If I want to do this with
constexpr
, each
.h / .cpp file combination must have all of the code in it for all the supported platforms. So each file becomes 2 to 5 times (or more) larger, depending upon how many platforms are supported:
enum Platform { Apple, Windows };
constexpr Platform platform = Apple;
void createWindow() {
if (platform == Apple) {
}
else if (platform == Windows) {
}
}
Am I missing something, like a way to include a file based on a
constexpr
, so the individual files don't get bloated? Are there other drawbacks to using
constexpr
in that manner besides large file sizes if my understanding is correct? Do modules offer a better solution to this problem?
Thanks!
What I have tried:
Some reading on
constexpr
, but not a lot.