From 208f5b870d870251ae2aadb87b7cf055e87f213b Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sat, 18 Sep 2021 11:58:02 +0000 Subject: [PATCH] containers.dynamicarray: Fix with allocators without `reallocate` Use UFCS to pull in the top-level fallback when the method is absent. --- src/containers/dynamicarray.d | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/containers/dynamicarray.d b/src/containers/dynamicarray.d index fce240c..da14bdb 100644 --- a/src/containers/dynamicarray.d +++ b/src/containers/dynamicarray.d @@ -130,6 +130,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange static if (useGC) void* oldPtr = arr.ptr; void[] a = cast(void[]) arr; + import std.experimental.allocator.common : reallocate; allocator.reallocate(a, c * T.sizeof); arr = cast(typeof(arr)) a; static if (useGC) @@ -247,6 +248,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange static if (useGC) void* oldPtr = arr.ptr; void[] a = cast(void[]) arr; + import std.experimental.allocator.common : reallocate; allocator.reallocate(a, c * T.sizeof); arr = cast(typeof(arr)) a; static if (useGC) @@ -682,3 +684,15 @@ version(emsi_containers_unittest) @nogc unittest a.resize(1); assert(a[0].i == 42); } + +version(emsi_containers_unittest) unittest +{ + import std.experimental.allocator.building_blocks.region : Region; + auto region = Region!Mallocator(1024); + + auto arr = DynamicArray!(int, Region!(Mallocator)*, true)(®ion); + // reserve and insert back call the common form of reallocate + arr.reserve(10); + arr.insertBack(1); + assert(arr[0] == 1); +}