'new' class method

Steven Schveighoffer schveiguy at yahoo.com
Thu Oct 23 13:07:07 PDT 2008


"Bill Baxter" wrote
> To me this makes a lot of sense:
>
> auto a = SomeStruct();  // a is a struct on the stack
> auto b = SomeClass();  // b is a class on the heap
>
> It kills static opCall for classes, but who cares.  I'm often tempted
> to write static opCalls for classes like this anyway:
>    static SomeClass opCall() {  return new SomeClass(); }
>
> Just to get the uniformity of construction syntax.

It also cleans up this ugliness:

auto data = (new FileInput(filename)).readAll();

Which then becomes:

auto data = FileInput(filename).readAll();

-Steve 





More information about the Digitalmars-d mailing list