Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 25, 2015 When to use typecons.proxy vs alias this? | ||||
---|---|---|---|---|
| ||||
I can't find much documentation/usage of typecons.proxy, but it seems extremely similar to alias this. The documentation page( http://dlang.org/library/std/typecons/proxy.html ) doesn't really seem to elaborate on this at all. |
January 25, 2015 Re: When to use typecons.proxy vs alias this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to weaselcat | Use alias this if you want implicit conversions too. Proxy keeps the types separate void foo(Base b) { } struct Modified { Base b; alias b this; } foo(Modified()); //works That wouldn't work if it was proxied though, which you sometimes want to force everything to go through your modification. |
January 25, 2015 Re: When to use typecons.proxy vs alias this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Sunday, 25 January 2015 at 03:55:18 UTC, Adam D. Ruppe wrote:
> Use alias this if you want implicit conversions too.
>
> Proxy keeps the types separate
>
> void foo(Base b) { }
>
> struct Modified {
> Base b;
> alias b this;
> }
>
> foo(Modified()); //works
>
>
> That wouldn't work if it was proxied though, which you sometimes want to force everything to go through your modification.
So the only difference is that proxy doesn't have implicit conversions? Hm. Might be worth pointing out on the docs.
|
January 26, 2015 Re: When to use typecons.proxy vs alias this? | ||||
---|---|---|---|---|
| ||||
Posted in reply to weaselcat | On Sunday, 25 January 2015 at 05:57:37 UTC, weaselcat wrote:
> So the only difference is that proxy doesn't have implicit conversions? Hm. Might be worth pointing out on the docs.
I don't think it is the *only* difference - the implementations are very different - but I do think it is the most significant one.
|
Copyright © 1999-2021 by the D Language Foundation