Importing version identifiers from another file?
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Apr 12 17:34:12 UTC 2022
On Tue, Apr 12, 2022 at 10:07:15AM -0700, Ali Çehreli via Digitalmars-d-learn wrote:
> On 4/11/22 01:57, KytoDragon wrote:
>
> > Is there any way to import version specifiers from a separate file?
>
> Have you tried mixing in the versions? Have one file with the versions
> in it:
>
> // file: 'versions'
> version = x;
>
> Then mix it in:
>
> mixin (import ("versions"));
>
> version (x) { /* ... */ }
>
> Seems to work for me.
[...]
If you need globally-defined versions, I'd just use the command-line
option `-version=MyVersionA -version=MyVersionB ...`.
Or, if you absolutely have to define versions in a source file, why not
just use enums + static if instead:
// versions.d
module versions;
enum MyVersionA = true;
enum MyVersionB = true;
// program.d
import versions;
static if (MyVersionA) {
...
} else {
...
}
// ... and so on
T
--
An elephant: A mouse built to government specifications. -- Robert Heinlein
More information about the Digitalmars-d-learn
mailing list