'new' class method

bearophile bearophileHUGS at lycos.com
Thu Oct 23 13:44:19 PDT 2008


Bill Baxter:
> How about this as a start:
> 
> // Default cases
> auto a = SomeStruct(arg);  // struct on the stack
> auto a = SomeClass(arg);  // class on the heap
> 
> // Anti-default cases
> auto a = SomeStruct.new(arg);  // struct on the heap
> scope a = SomeClass(arg);  // class on the stack
> 
> // Placement cases
> ...

I agree that the placement new syntax can be less nice.

But for the struct/class cases I'd like something more symmetric :-)
A first silly possibility:

auto a = SomeStruct(arg); // stack
auto a = SomeStruct.new(arg); // heap
auto a = SomeStruct.pnew(placement_arg)(arg); // placement
A possible alternative:
auto a = SomeStruct.pnew(placement_arg).new(arg); // placement

auto a = SomeClass(arg); // stack
auto a = SomeClass.new(arg); // heap
auto a = SomeClass.pnew(placement_arg)(arg); // placement
A possible alternative:
auto a = SomeClass.pnew(placement_arg).new(arg); // placement

Bye,
bearophile



More information about the Digitalmars-d mailing list