Eponymous/anonymous mixin templates

Jeffrey Tsang via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 8 08:14:08 PDT 2015


On Sunday, 7 June 2015 at 14:17:45 UTC, Artur Skawina wrote:
> On 06/07/15 11:05, Jeffrey Tsang via Digitalmars-d wrote:
>> I use a mixin template to define exactly one symbol, and at 
>> instantiation I wish to use that symbol immediately, once.
>
> AFAICT you're asking for the commented-out line in
>
>    auto Tmpl() = l;
>
>    void main(string[] argv) {
>       auto l = argv.length;
>       mixin Tmpl!() a;
>       assert(a.Tmpl==l);
>       //assert(a==l);
>    }
>
> to work. That would probably be enough, make sense and have
> no serious backward compat issues.
>
> artur

There are three separate things I would like to have:

1. Eponymous trick

mixin T foo(T)() {
     return bar;
}

as pure syntactic sugar for

mixin template foo(T) {
     T foo() {
         return bar;
     }
}

2. Eponymous trick, calling end

mixin foo!T;

to also include as syntactic support

alias foo = foo!T.foo;

as well as the named version you listed.

3. Inline/anonymous mixins

Some way of writing the equivalent of

bar = (mixin foo!T)() + 3;

inline as an expression, the same way as

bar = regular_template_foo!T() + 3;


More information about the Digitalmars-d mailing list