__traits(compiles, ...) with syntax errors

Olivier FAURE couteaubleu at gmail.com
Tue Jan 15 13:15:25 UTC 2019


On Tuesday, 15 January 2019 at 01:59:58 UTC, Steven Schveighoffer 
wrote:
>
> I don't want to do this, but a compiler feature that allowed it 
> would be cool. Having to make copies of templates to be able to 
> debug things is so horrid.
>
> -Steve

Maybe a sub-name system? Like:

     T* myFunc.withFoo(T)(T t) if(__traits(compiles, t.foo()));
     T* myFunc.withBar(T)(T t) if(__traits(compiles, t.bar()));

Then if you call `myFunc.withFoo(t)`, you get something like:

    Error: Cannot call withFoo overload of myFunc
    Error: because constraint if(__traits(compiles, t.foo())) is 
not satisfied

(it would be especially helpful with the "multiple constraints" 
DIP)

It would probably be pretty hard to implement, and make name 
resolution even more complicated, though.


More information about the Digitalmars-d mailing list