std.allocator ready for some abuse

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Oct 24 17:01:21 PDT 2013


On 10/24/13 2:38 PM, Namespace wrote:
> On Thursday, 24 October 2013 at 21:31:42 UTC, Namespace wrote:
>> Awesome! Will Appender get an option to use a suitable allocator?
>
> A dream of me, that will probably never come true, would be also
> something like this:
> ----
> with (Mallocator) {
>      int[] arr;
>      arr ~= 42; /// will use Mallocator.it.allocate internal
> }
> ----

Oddly enough this can be actually done.

with (setAllocator!Mallocator)
{
    ...
}

setAllcator returns an rvalue that changes the global allocator to the 
Mallocator in the constructor, and restores it to whatever it was in the 
destructor.


Andrei



More information about the Digitalmars-d mailing list