is(x = module) vs. __traits(isModule, x)

Stefan Koch uplink.coder at googlemail.com
Wed Oct 7 20:41:19 UTC 2020


On Wednesday, 7 October 2020 at 20:37:47 UTC, Meta wrote:
> On Wednesday, 7 October 2020 at 20:19:57 UTC, Paul Backus wrote:
>> Couldn't you unconditionally lower <Node>.__isModule to 
>> __traits(isModule, <Node>) regardless of what type of node it 
>> is, and rely on the existing error messages for incorrect 
>> trait arguments? You don't have to worry about shadowing 
>> "real" properties, because anything that starts with "__" is a 
>> reserved identifier.

>     if (__traits(compiles, mixin(`__traits(%s, sym, 
> Args)`.format(name))))
>     {
>         enum opDispatch = mixin(`__traits(%s, sym, 
> Args)`.format(name));
>     }
> }


As a little side notion.
Avoid the use of std.format.format at CTFE.
It's very expensive.
And please cache the string :)


More information about the Digitalmars-d mailing list