multiple `alias this` suggestion

Carl Sturtivant via Digitalmars-d digitalmars-d at puremagic.com
Sat Apr 29 16:57:07 PDT 2017


On Thursday, 27 April 2017 at 05:41:43 UTC, Daniel N wrote:
> On Wednesday, 26 April 2017 at 18:34:48 UTC, Carl Sturtivant 
> wrote:
>> On Wednesday, 26 April 2017 at 15:00:30 UTC, Steven
> Image using frameworks which conveniently allow adding features 
> to a struct...
>
> struct Beholder
> {
>   mixin Entity!Movable;
>   mixin Render!"Beholder.png";
> }

Why distribute features as mixin templates when with AliasThis 
fully implemented they can be distributed as structs and are 
therefore encapsulated?

struct Beholder
{
     //now Entity(T) is a struct template, not a mixin template
   Entity!Movable entity;
     //ditto
   Render!"Beholder.png" render;
     //in my hierarchical form
   alias entity, render this;
}

Even better, with alias for embedded aliased-to-this structs made 
working usefully, name management can be done before embedding 
the features, by having another layer of embedding as in my 
earlier example here.
https://forum.dlang.org/post/hvdmtvjvccbkmkjzuclm@forum.dlang.org

Broadly speaking, a mixin template is just "a bunch of 
unencapsulated declarations". And AliasThis is a way to remove a 
layer of encapsulation from "a bunch of declarations". (Though it 
cannot be used currently outside of a struct or class.) This just 
screams for simplification.



More information about the Digitalmars-d mailing list