Feature request: __traits(canInstantiate), like __traits(compiles) but without suppressing syntax errors
John Colvin
john.loughran.colvin at gmail.com
Fri Jan 17 15:02:18 UTC 2020
On Wednesday, 15 January 2020 at 15:13:08 UTC, FeepingCreature
wrote:
> Right now it's impossible to check "is there a valid (template)
> specialization for this function call" without also saying "and
> by the way, if there's a syntax error in the function, suppress
> the error and return false."
>
> This makes many Phobos and library functions very annoying to
> use.
>
> A simple (?) fix for this would be adding a new trait that
> checks if the expression resolves to a valid template
> specialization, without attempting to also check if the
> function body compiles, or else without suppressing internal
> syntax errors.
Yes please (although I would say specialization and constraints,
for all templates).
I worked around this in a commercial project a few years ago by
creating an overload set of the passed symbol and a catch-all
template, then instantiate and see if I got the catch-all
(meaning no match), but obviously this is pretty nasty and
doesn't work if one of the overloads of the original template is
a catch-all as well.
More information about the Digitalmars-d
mailing list