change mixins
Denis Koroskin
2korden at gmail.com
Sun Feb 14 14:39:02 PST 2010
On Mon, 15 Feb 2010 00:31:29 +0300, Walter Bright
<newshound1 at digitalmars.com> wrote:
> Right now, mixins are defined and used as:
>
> template foo(T) { declarations... }
>
> mixin foo!(int) handle;
>
> The proposal is to switch it around:
>
> mixin template foo(T) { declarations... }
>
> foo!(int) handle;
>
> to follow the notion that mixin templates are very different from
> regular templates, and that should be reflected in their definition
> rather than use.
>
> What do you think?
I support the change, expect that I believe mixing in the mixin template
should involve the "mixin" keyword.
In fact, I have proposed exactly the same more that a year ago. Here is a
quote:
Usually templates and mixin templates are completely
different, mixin'ing usual template or instantiating template that is
intended for being mixed-in makes no sense in the majority of real cases.
Moreover, I would prefer to separate these terms and so their syntax:
mixin template Bar
{
private int value;
public int getValue() { return value; }
}
class Foo
{
mixin Bar!();
}
int bar = Bar!().getValue(); // Error: can't instantiate mixin template
template Square(alias x)
{
private enum temp = x * x;
public enum Square = temp;
}
class Test
{
mixin Square!(42); // Error: can't mixin non-mixin template
}
More information about the Digitalmars-d
mailing list