"This for <member> needs to be type <class>, not type <otherclass>"
Simen Kjaeraas
simen.kjaras at gmail.com
Fri May 2 10:39:38 PDT 2008
Jarrett Billingsley Wrote:
> "Simen Kjaeraas" <simen.kjaras at gmail.com> wrote in message
> news:fvfg2g$1nnp$1 at digitalmars.com...
> > While playing around with templates and alias parameters, I got the die of
> > trying this:
> >
> > struct foo(alias T)
> > {
> > typeof(T) opAddAssign(typeof(T) rhs)
> > {
> > return T += rhs;
> > }
> > }
>
> If you make this a template:
>
> template foo(alias T)
> // rest is the same
>
> >
> > class bar
> > {
> > private:
> > int _baz;
> > public:
> > foo!(_baz) baz;
>
> And now change this to a mixin:
>
> mixin foo!(_baz) baz;
>
> It works.
>
> Of course, this has the effect of making foo (or rather an instance of foo)
> no longer a type. But maybe you don't need it to be.
Now why didn't I think of that... I have to say the mixin syntax is uglier, but it gets the job done.
There are times when I wish I could declare a function, template or whatever to be a mixin type, so any instantiation of it would be a mixin. If that were to be implemented, I wouldn't have the ugly 'mixin' keyword cluttering my code. It would make code cleaner, but mayhaps more hard to read.
-- Simen
More information about the Digitalmars-d-learn
mailing list