Thread overview |
---|
October 11, 2017 Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
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. |
October 13, 2017 Re: Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | 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.
I don't see how compiler can just deduce that... In either case you can just wrap the expression with another Bar():
auto v5 = Bar(Bar(Foo(2)) + Bar(Foo(3)));
|
October 14, 2017 Re: Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | 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. |
October 14, 2017 Re: Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | On Saturday, 14 October 2017 at 11:25:20 UTC, Alex wrote: of course, with the proper operator in line 32 return T(mixin("this" ~ op ~ "f")); https://run.dlang.io/is/jGKVYN |
October 14, 2017 Re: Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | On Saturday, 14 October 2017 at 12:39:17 UTC, Alex wrote: ok, the last version for now. Without assumptions on alias number. Sorry for noise. https://run.dlang.io/is/OSJYtY |
October 14, 2017 Re: Two way struct wrapper | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | 14.10.2017 16:23, Alex пишет: > On Saturday, 14 October 2017 at 12:39:17 UTC, Alex wrote: > > ok, the last version for now. Without assumptions on alias number. Sorry for noise. > > https://run.dlang.io/is/OSJYtY That's cool, but unfortunately demands access to source code of Foo, it's not my case( I improved your example a little bit - https://run.dlang.io/is/yeKofN, it's really great. Need polish of course, but this is a way to get more inheritance with structures. |
Copyright © 1999-2021 by the D Language Foundation