Feature request: __traits(canInstantiate), like __traits(compiles) but without suppressing syntax errors
user1234 at 1234.de
Wed Jan 22 18:24:17 UTC 2020
On Tuesday, 21 January 2020 at 22:32:45 UTC, Steven Schveighoffer
> On 1/18/20 10:21 AM, FeepingCreature wrote:
>> Yes it can!
>> D already has support for exactly this kind of thing, with
>> std.traits and `if()` constraints. If you have a metafunction
>> that tries to see if "an alias is usable with string", and it
>> checks that with __traits(canInstantiateCall, foo,
>> string.init) or whatever, then you *should* get a syntax error
>> even in the "return x + 5" case. If you want to avoid that, we
>> don't need language changes, you just need to use the *already
>> existing* mechanism of "if (isNumeric!T)".
> Wait, I think I get it.
> You want something that says if the constraints allow the
> instantiation to proceed, then instantiate, and display the
> errors as generated. If not, then return false.
Yes and there's an API for that
More information about the Digitalmars-d