Difference between "can call" and "can compile"
schveiguy at gmail.com
Wed Sep 16 00:28:59 UTC 2020
On 9/15/20 8:20 PM, Jackel wrote:
> On Tuesday, 15 September 2020 at 19:12:04 UTC, Steven Schveighoffer wrote:
>> I could probably switch to using "hasMember" in this use case, which
>> is likely to be correct for all purposes that I have. It's just not
>> applicable to a public library, which might use things other than
> You mentioned UFCS, but if it is a template in a library then user
> defined UFCS shouldn't work. The only valid case I can think of would be
> for a built in array, using front() and friends. But the library would
> have to import those functions for it to work.
Yes, but input ranges and Phobos are not the only things that depend on
There's also a question of whether a free function can be called with a
provided type, which has no analogue to __traits(hasMember).
> I do agree with what you are saying, in fact it almost seems like
> __traits(compiles) is a code smell. There's usually a better way to
> express it, and as is with the case you are talking about, a different
> feature would be more appropriate and provide better error messages.
Yes, exactly. I've spent way more than my fair share unraveling via
library surgery what the compiler should be able to do itself, as long
as the proper tools existed.
Don't get me wrong, I'd be fine with a solution that doesn't need a new
feature (that would be ideal actually).
More information about the Digitalmars-d