How would you do this in D?

Jonathan M Davis jmdavisProg at gmx.com
Tue May 10 18:09:29 PDT 2011


On 2011-05-10 17:55, Jose Armando Garcia wrote:
> Good suggestion but I dislike the syntax for mixin template for this
> use case. It looks like:
> 
> bool every(string file = __FILE__, int line = __LINE__)(int time)
> {
>    static int counter;
>    if(++counter > time) counter -= time;
> 
>    return counter == 1;
> }
> 
> works just fine. Hmmm!

Use whatever works best for you, but I would point out that template mixins 
and string mixins are completely different. I said string mixin and you 
mentioned template mixin. Both have their advantages and disadvantages, but 
they're two separate things. But yes, if you can do it with a normal template, 
that will likely result in prettier-looking code.

- Jonathan M Davis


More information about the Digitalmars-d mailing list