Skip to content

Commit 208f5b8

Browse files
committed
containers.dynamicarray: Fix with allocators without reallocate
Use UFCS to pull in the top-level fallback when the method is absent.
1 parent c0e932a commit 208f5b8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/containers/dynamicarray.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
130130
static if (useGC)
131131
void* oldPtr = arr.ptr;
132132
void[] a = cast(void[]) arr;
133+
import std.experimental.allocator.common : reallocate;
133134
allocator.reallocate(a, c * T.sizeof);
134135
arr = cast(typeof(arr)) a;
135136
static if (useGC)
@@ -247,6 +248,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
247248
static if (useGC)
248249
void* oldPtr = arr.ptr;
249250
void[] a = cast(void[]) arr;
251+
import std.experimental.allocator.common : reallocate;
250252
allocator.reallocate(a, c * T.sizeof);
251253
arr = cast(typeof(arr)) a;
252254
static if (useGC)
@@ -682,3 +684,15 @@ version(emsi_containers_unittest) @nogc unittest
682684
a.resize(1);
683685
assert(a[0].i == 42);
684686
}
687+
688+
version(emsi_containers_unittest) unittest
689+
{
690+
import std.experimental.allocator.building_blocks.region : Region;
691+
auto region = Region!Mallocator(1024);
692+
693+
auto arr = DynamicArray!(int, Region!(Mallocator)*, true)(&region);
694+
// reserve and insert back call the common form of reallocate
695+
arr.reserve(10);
696+
arr.insertBack(1);
697+
assert(arr[0] == 1);
698+
}

0 commit comments

Comments
 (0)