Dlang equivalent of #define/#ifdef : not... version

Ali Çehreli acehreli at yahoo.com
Tue Apr 20 22:28:22 UTC 2021


On 4/20/21 3:03 PM, Simen Kjærås wrote:
> On Tuesday, 20 April 2021 at 18:57:46 UTC, ichneumwn wrote:
>> So my questions:
>> - is there a module-crossing equivalent of "version"?
> 
> mw covered this. There's more documentation here: 
> https://dlang.org/spec/version.html#version
> https://dlang.org/dmd-windows.html#switch-version
> 
> 
>> - if not, is there some way I could test for the existence of the enum 
>> can_i_test_for_this? A SymbolExists!() or ModuleHasSymbol!() or 
>> ModuleHasMember!() ?
> 
> __traits(hasMember, features, "i_am_not_a_feature")
> 
> This is actually what std.traits.hasMember does, but for some reason it 
> can't take a module as its first argument.
> 
> -- 
>    Simen

Could it be because __MODULE__ is string, requiring mixin? The following 
prints 'true':

enum i_am_not_a_feature = 42;

pragma(msg, __traits(hasMember, mixin(__MODULE__), "i_am_not_a_feature"));

Ali



More information about the Digitalmars-d-learn mailing list