kwargs v0.0.1 - Keyword arguments with strong types

Vladimir Marchevsky vladimmi at gmail.com
Mon Feb 11 22:32:59 UTC 2019


On Monday, 11 February 2019 at 17:03:36 UTC, Atila Neves wrote:
> import kwargs;
>
> struct Foo { string value; }
> struct Bar { string value; }
> struct Baz { string value; }
>
> size_t funImpl(in Foo foo, in Bar bar = Bar("lebar"), in Baz 
> baz = Baz("lebaz")) {
>     return foo.value.length + bar.value.length + 
> baz.value.length;
> }
>
> alias fun = kwargify!funImpl;
>
> fun(Foo()).should == 10;
> fun(Bar("b"), Foo("fo")).should == 8;
> fun(Bar("b"), Baz("ba"), Foo("foo")).should == 6;

So all arguments should have different types, right? Like here we 
have 3 strings wrapped in structs to distinguish them


More information about the Digitalmars-d-announce mailing list