Feature request: __traits(canInstantiate), like __traits(compiles) but without suppressing syntax errors

Steven Schveighoffer schveiguy at gmail.com
Thu Jan 16 16:00:03 UTC 2020


On 1/15/20 10:13 AM, 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."

I know what you mean, but they are not syntax errors (which ARE errors, 
even in templates). Which makes them really difficult to categorize.

> 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.

Generally, I use hasMember instead of __triats(compiles) and I'm better 
off for it. If something defines a member by a specific name, then it 
better be what I'm looking for, so try using it. If not, then you'll 
just have to name it something else. I'm not sure Phobos can take this 
road though.

-Steve


More information about the Digitalmars-d mailing list