diff options
Diffstat (limited to 'source/tanya/memory/package.d')
| -rw-r--r-- | source/tanya/memory/package.d | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/source/tanya/memory/package.d b/source/tanya/memory/package.d index 60a45a6..3979fe0 100644 --- a/source/tanya/memory/package.d +++ b/source/tanya/memory/package.d @@ -220,15 +220,26 @@ void dispose(T)(shared Allocator allocator, auto ref T p) } /// Ditto. -void dispose(T)(shared Allocator allocator, auto ref T[] array) +void dispose(T)(shared Allocator allocator, auto ref T[] p) { - static if (hasElaborateDestructor!(typeof(array[0]))) + static if (hasElaborateDestructor!(typeof(p[0]))) { - foreach (ref e; array) - { - destroy(e); + import std.algorithm.iteration; + p.each!(e => destroy(e)); } + () @trusted { allocator.deallocate(p); }(); + p = null; +} + +unittest +{ + struct S + { + ~this() + { + } } - () @trusted { allocator.deallocate(array); }(); - array = null; + auto p = cast(S[]) defaultAllocator.allocate(S.sizeof); + + defaultAllocator.dispose(p); } |
