Testing whether static foreach is available
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 9 10:32:54 PDT 2017
On Saturday, 9 September 2017 at 16:30:51 UTC, Jean-Louis Leroy
wrote:
> I did look at the docs, several times, couldn't find it...
you should use my unofficial docs
http://dpldocs.info/version
std.compiler looks useful
http://dpldocs.info/experimental-docs/std.compiler.version_minor.html
static foreach was introduced in 2.076 so
import std.compiler;
static if(version_minor >= 76) {
// it is available
}
BUT, this won't do what I suspect you want... if you put a static
foreach in there and compile with an old compiler... it will
still cause a parse error.
The false branch of a static if still need to parse correctly,
and static foreach won't in old D.
You can work around that by perhaps importing alternative modules
or using string mixin that contains the new code (similar
techniques for libs that are both D1 and D2 compatible)
More information about the Digitalmars-d
mailing list