struct mixins

Leandro Lucarella llucax at gmail.com
Mon Nov 16 09:56:04 PST 2009


Denis Koroskin, el 16 de noviembre a las 19:03 me escribiste:
> On Mon, 16 Nov 2009 18:58:42 +0300, Frank Benoit
> <keinfarbton at googlemail.com> wrote:
> 
> >Reminds me of an older thread:
> >http://www.digitalmars.com/d/archives/digitalmars/D/Implicit_castable_structs_64764.html
> 
> I recall it, but I still think "alias this" is the way to go:
> 
> struct GtkWidget{ /* data member */ }
> 
> struct GtkContainer{
>     GtkWidget widget; // mixin GtkWidget; could also work, though
>     // more data members
> 
>     alias this &widget; // how would you do the same without a named mixin?
>     // And what's the benefit of named mixin over plain old aggregation?
> }

See how a struct mixin could add an implicit/explicit cast to the mixed in
structs.

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Con vos hay pica, patovica!
	-- Sidharta Kiwi



More information about the Digitalmars-d mailing list