On Sunday, 25 February 2018 at 01:19:02 UTC, Seb wrote:
On Sunday, 25 February 2018 at 00:42:20 UTC, Seb wrote:
On Sunday, 25 February 2018 at 00:36:16 UTC, kdevel wrote:
   [...]

Are you looking for something like this?

---
static if (__traits(compiles, () { static foreach (i; [0]){} }))
    version = supportsStaticForeach;

void main()
{
    version(supportsStaticForeach) {
       pragma(msg, "Yay, your compiler is new enough.");
    }
}
---


https://run.dlang.io/is/PZN5Nv

[...]

Don't support GDC (or only GDC-master)?

Ah sorry I replied too fast. Yeah `mixin` is the only way to workaround this if you really, really have to support GDC.

BTW there's one trick that might work on your setup - conditional imports:

---
static if (__traits(compiles, () { static foreach (i; [0]){} }))
    version = supportsStaticForeach;

void main()
{
    version(supportsStaticForeach) {
       import compat.staticforeach;
    } else {
       import compat.no_staticforeach;
    }
}
---

With rdmd this should work out of the box - with DUB you would need to tweak the source paths. DUB allows all options to be compiler-specific, so e.g. something like this for a dub.sdl could work:

---
sourcePaths-dmd "compat/staticforeach"
sourcePaths-ldc "compat/staticforeach"
sourcePaths-gdc "compat/no_staticforeach"
---

Reply via email to