Named parameters

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 08:39:32 PDT 2015


On Sat, 25 Jul 2015 17:16:23 +0200
Johannes Pfau via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> Named boolean flags are only one very common special case though. That
> solution doesn't work that well for integers:
> 
> auto w = Window(0, 0, 100, 200);
> auto w = Window(x = 0, y = 0, width = 100, height = 200);
> //auto w = Window(x.0, y.0, width.100, height.200);
> 
> You could introduce new types for X,Y, Width, Height:
> auto w = Window(X(0), Y(0), Width(100), Height(200));

auto w = Window(Position(0,0), Dimension(100, 200)); // this is what I prefer

but if someone want to be more explicit:

auto w = Window(Position.x(0).y(0), Dimension.width(100).height(200));


More information about the Digitalmars-d mailing list