Testing whether static foreach is available
Moritz Maxeiner via Digitalmars-d
digitalmars-d at puremagic.com
Sun Sep 10 05:03:10 PDT 2017
On Sunday, 10 September 2017 at 01:49:42 UTC, Mike Parker wrote:
> On Saturday, 9 September 2017 at 16:53:19 UTC, jmh530 wrote:
>
>> version(DLANGSEMVER >= 2.076.0)
>> {
>> //include static foreach code.
>> }
>>
>> but we can't do conditionals in version blocks, so you'd need
>> a static if. Alternately, we'd also need a trait or something
>> to get the semver of the compiler.
>
> Actually:
>
> static if(__VERSION__ >= 2076)
>
> Better to use this than the compiler version, as it specifies
> the version of the front end, so when LDC and GDC catch up it
> will work for those as well.
If __VERSION__ is *guaranteed* to be the language frontend
version (and testing shows it is in dmd, ldc, and gdc, at least),
shouldn't the spec [1] state that (right now it's only required
to be some generic "compiler version")?
[1] https://dlang.org/spec/lex.html#specialtokens
More information about the Digitalmars-d
mailing list