D - Consider Generic/Template Modules
- Matthias Spycher (28/28) Jan 25 2004 For example:
- Walter (24/52) Jan 26 2004 You can do this now:
- Matthias Spycher (9/75) Jan 26 2004 Very cool indeed!
For example: module A (T, alias M : module) { private import M; class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, this); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes. In other words, one can configure a module with the symbols from another. I'm not sure how complicated this feature is to implement -- is it as bad as general support for ADL. One could view it as a mechanism for selective ADL. I believe they call it higher-order functors in some languages like SML. Matthias
Jan 25 2004
You can do this now: module A (T, alias M) { class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, B); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- "Matthias Spycher" <matthias coware.com> wrote in message news:bv0po5$2ro4$1 digitaldaemon.com...For example: module A (T, alias M : module) { private import M; class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, this); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes. In other words, one can configure a module with the symbols from another. I'm not sure how complicated this feature is to implement -- is it as badasgeneral support for ADL. One could view it as a mechanism for selectiveADL.I believe they call it higher-order functors in some languages like SML. Matthias
Jan 26 2004
Very cool indeed! I was thinking about a module configuration pattern that would allow us to do AspectD using generic modules, but I have to give it some more thought... Cheers Matthias "Walter" <walter digitalmars.com> wrote in message news:bv4cev$2khv$1 digitaldaemon.com...You can do this now: module A (T, alias M) { class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, B); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- "Matthias Spycher" <matthias coware.com> wrote in message news:bv0po5$2ro4$1 digitaldaemon.com...InFor example: module A (T, alias M : module) { private import M; class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, this); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes.badother words, one can configure a module with the symbols from another. I'm not sure how complicated this feature is to implement -- is it asasgeneral support for ADL. One could view it as a mechanism for selectiveADL.I believe they call it higher-order functors in some languages like SML. Matthias
Jan 26 2004