Problems using 'with' statement

bearophile bearophileHUGS at lycos.com
Sat Jan 4 13:51:05 PST 2014


Adam S:

> Most template member funs seems to work fine. The issue only 
> seems to appear when the member function is overloaded. For 
> example
>
> class Foo {
>     auto test(alias val)() if (is(typeof(val) == int)){}
>     //auto test(alias val)() if (!is(typeof(val) == int)){}
>
> }
>
> void main() {
>     auto bar = new Foo;
>
>     with (bar) {
>         test!2();      //works
>     }
> }
>
> works fine until the overload of test is uncommented. Then the 
> same error occurs.

with() was designed and created to access fields of structs in a 
simpler way. In D also enum and class members are usable with 
with(). Your use case seems a corner case of a usage pattern that 
was not included. So perhaps you have to write an enhancement 
request.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list