Writing platform-specific code (versions) and per-client configuration modules
Different platforms often need specialized code. D provides the version
statement for this case, which is similar to but cleaner than C's #ifdef
directives. In addition to platforms, special code may be needed when building customized versions of an application for a specific client or other special case. While version
can do that job, it isn't ideal. So, we'll use another technique: configuration modules.
How to do it…
Writing platform-specific code and writing client-specific code is best done with two different techniques.
Platform-specific code
Perform the following steps:
Write
version
statements for all supported platforms.Write
else static assert(0, "Unsupported platform");
at the end of the version list.Don't try to mix partial declarations for different platforms together, it will be more trouble than it is worth.
The code is as follows:
version(Windows) void writeToFile(HANDLE file, in void[] data) { if(...