Two way struct wrapper

Alex sascha.orlov at gmail.com
Sat Oct 14 11:25:20 UTC 2017


On Wednesday, 11 October 2017 at 12:35:51 UTC, drug wrote:
> Using `alias this` it's easy to make wrapper for structure that 
> calls wrapped structure methods like its own. This is one way - 
> from wrapper to wrapped transformation. Is it possible to 
> create the opposite way from wrapped to wrapper?
>
> https://run.dlang.io/is/Avyu3I
>
> All calls to Bar is redirected to Foo, but output of Foo is not 
> redirected to Bar.

How about a template for the opBinary operator?
https://run.dlang.io/is/7gi5Wl

The code relies on the fact, that only one alias this is allowed.
https://dlang.org/spec/class.html#AliasThis

If more are possible at some moment, I suppose it will be 
possible to static foreach over them to choose the right member, 
based on its type.


More information about the Digitalmars-d-learn mailing list