Cannot dup an associative array but why?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 11 14:23:28 PDT 2017


On 07/11/2017 01:25 PM, Jean-Louis Leroy wrote:
 > On Tuesday, 11 July 2017 at 17:20:33 UTC, Ali Çehreli wrote:
 >
 >> @Virtual("t", "d", "w")
 >> string fight(Character t, Dragon d, Hands w) {
 >>     return "you just killed a dragon with your bare hands. Incredible
 >> isn't it?";
 >> [...]
 >> mixin ProcessMethods();
 >
 > Great suggestion! I think this could work:
 >
 >   string fight(virtual!Character, virtual!Creature, virtual!Device); //
 > declares method
 >
 >   // define implemention:
 >   string fight(Character t, Dragon d, Hands w);
 >
 >   mixin ProcessMethods();
 >
 > How do you find the current module inside ProcessMethods?

Default template and function arguments are resolved at instantiation 
site, which means __MODULE__ would resolve automatically to the caller's 
module. For example, if you have this module:

------------------
module a;

mixin template ProcessMethods(string mod = __MODULE__) {
     enum s = "Working with " ~ mod;
}
------------------

The user can simply mix it in:

------------------
module deneme;

import a;

mixin ProcessMethods;

void main() {
     pragma(msg, s);
}
------------------

And the string has the user's module 'deneme':

Working with deneme

Ali



More information about the Digitalmars-d-learn mailing list