Composing features at compile time

Philippe Sigaud philippe.sigaud at gmail.com
Sun Nov 24 11:53:31 PST 2013


On Sun, Nov 24, 2013 at 6:25 PM, Dicebot <public at dicebot.lv> wrote:
> On Sunday, 24 November 2013 at 14:23:55 UTC, Philippe Sigaud wrote:
>>
>> But how do you use policies to inject different code in different
>> places of your struct?
>
>
> Don't really get the question. Isn't it what policies do pretty much by
> definition? You decompose part of target functionality into smaller blocks
> with optional behavior (including no-op behavior) and provide specific ones
> as alias parameters. D has additional benefit of being able to use one as
> template mixin for cleaner syntax. But I am pretty sure you know this, so
> what is the question again? :)

Hmm. Then you still need to define where the policy will act. OK, I
can get that. I thought the OP wanted something more flexible, where
different loggers could inject code at many different places.

But if there is no Logging policy asked for (the user doesn't care for
logging), you must insure that the default policy 'disappears', so to
speak. I'm not sure that's always possible.

>> auto foo = new Foo!StubLogger(); // "false" case
>So StubLogger would implement "info" but do nothing? How good would the compiler be at optimizing this?

Exactly.


More information about the Digitalmars-d-learn mailing list