is(x = module) vs. __traits(isModule, x)
Steven Schveighoffer
schveiguy at gmail.com
Thu Oct 8 17:55:21 UTC 2020
On 10/8/20 1:43 PM, Paul Backus wrote:
> On Thursday, 8 October 2020 at 16:49:50 UTC, Steven Schveighoffer wrote:
>>
>> If we got type functions, and have UFCS, isn't this as easy as e.g.:
>>
>> bool isModule(alias x) { return __traits(isModule, x); }
>>
>> static assert(std.stdio.isModule);
>
> Ok, now do __traits(getMember, variable, "foo") and __traits(compiles,
> expression). :)
I did getMember already.
And it can't do __traits(compiles). So, just use __traits(compiles) for
that one.
> Using type functions to wrap __traits has the same issues as using
> templates to wrap __traits. In the common case, it works, but in the
> general case, it fails, because __traits have special privileges that no
> other construct in the D language (including templates, functions, and
> type functions) can fully imitate.
I'm not sure that's 100% true for type functions -- they aren't in there
yet.
-Steve
More information about the Digitalmars-d
mailing list