std.allocator needs your help

Benjamin Thaut code at benjamin-thaut.de
Wed Sep 25 12:42:22 PDT 2013


Am 25.09.2013 20:27, schrieb Johannes Pfau:
> Am Wed, 25 Sep 2013 17:22:28 +0200
> schrieb Benjamin Thaut <code at benjamin-thaut.de>:
>
>> Am 25.09.2013 00:39, schrieb Andrei Alexandrescu:
>>>
>>> We're banning that syntax of new.
>>>
>>> Andrei
>>
>> I always love it when people just plain ignore all the arguments I
>> made ...
>>
>
> I think there's a misunderstanding here. new(...) already was a valid
> syntax in D1, I think Andrei is referring to that:
>
> http://www.digitalmars.com/d/1.0/class.html#allocators
>
> And we really should get rid of that.
>
> The nested class/context pointer argument is a pretty strong one. Of
> course we could introduce builtins to deal with that but there's not
> much benefit to that.
>
> Having the compiler rewrite
>
> "new(MallocAllocator) MyClass(a,b,c)"
> to
> "void[] __buf = MallocAllocator.it.allocate(MyClass.instancesize);"
> "__construct!MyClass(__buf, a, b, c);" //Has to handle context ptr
>
> seems like a good solution. It probably has to support both allocator
> types(for allocators without state) and allocator instances.
>

Well I didn't actually know that a similar syntax existed in D1. I would 
be fine with a rewrite rule too. Anything that hides the syntactic 
unglyness of using a templated library method would be fine. We just 
have to make sure that the rewrite rule also correctly handles the 
implict conversion of literals. We might also want to allow:

MallocAllocator.new MyClass(a,b,c)

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d mailing list