shorter alternative of constructor with parameter
Chris Cain via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 23 10:17:19 PDT 2014
On Sunday, 22 June 2014 at 19:58:38 UTC, Kapps wrote:
> In theory, 'with' could be used for that if it returned the
> expression passed in:
> auto a = with(new Person()) {
> Name = "Bob";
> Age = 27;
> }
You forgot a semicolon after the } ... or at least that's what I
think it would need.
I kinda really like this. You could also do things like:
auto bob = with(PersonBuilder()) {
name = "Bob";
age = 27;
}.build();
with a `with` expression, to make it transactional instead. This
could do a lot of neat things, for sure.
More information about the Digitalmars-d
mailing list