'new' class method

KennyTM~ kennytm at gmail.com
Sat Oct 25 06:40:58 PDT 2008


KennyTM~ wrote:
> Bill Baxter wrote:
>> On Sat, Oct 25, 2008 at 2:04 AM, KennyTM~ <kennytm at gmail.com> wrote:
>>
>>>>  auto a = Class();  // heap   (default)
>>>>  auto a = Struct(); // stack   (default)
>>>>
>>>>  auto a = Class.new(stack)(); // stack
>>>>  auto a = Struct.new(stack)(); // stack
>>>>
>>>>  auto a = Class.new(heap)(); // heap
>>>>  auto a = Struct.new(heap)(); // heap
>>>>
>>>>   void *addr;
>>>>   auto a = Class.new(addr)(); // placement
>>>>   auto a = Struct.new(addr)(); // placement
>>>>
>>> I strongly *oppose* using stack and heap as keywords because there 
>>> are also
>>> (partly irrelevant) data structures called stack and heap, even though
>>> according to the guideline these class/structs should be named Stack and
>>> Heap.
>>
>> Right, that's why both Benji and I proposed making them *context*
>> keywords.  Just like "Windows" is a keyword only in the context of
>> extern( ).  This would make heap and stack keywords only in the
>> context of new(  ).
>>
> 
> I see. But with the your new(...) syntax this can't be done because it 
> is ambiguous with
> 
>   void* stack = allocate();
>   auto C = Class.new(stack)();
> 
> The placement new syntax should use some other syntax.
> 

or do it like this:

    auto C = Class.new(placement, addr, etc)();
//--------------------^ use this to specify it is a placement new.



More information about the Digitalmars-d mailing list