is(x = module) vs. __traits(isModule, x)
Paul Backus
snarwin at gmail.com
Thu Oct 8 17:43:31 UTC 2020
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). :)
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.
More information about the Digitalmars-d
mailing list