Composing features at compile time

Jacob Carlborg doob at me.com
Sun Nov 24 11:37:43 PST 2013


On 2013-11-24 18:31, Dicebot wrote:

> To clarify, OP example will look like this:
>
> class Foo (alias Logger)
>      if (isLoggger!Logger)
> {
>       private Logger logger;
>
>       this ()
>       {
>           logger = new Logger;
>       }
>
>       void action ()
>       {
>           logger.info("performing action");
>           // perform action
>       }
> }
>
> // ...
>
> auto foo = new Foo!StubLogger(); // "false" case

So StubLogger would implement "info" but do nothing? How good would the 
compiler be at optimizing this?

> It works better with compilers like LDC of course, because of good
> inlining and AST restructuring during optimization pass.


-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list