From d7a37659c3706ceed811d3b6476759acd9ed01ee Mon Sep 17 00:00:00 2001 From: Paul Backus Date: Sat, 3 Sep 2022 11:46:18 -0400 Subject: [PATCH] ae.utils.appender: check for Allocator.deallocate --- utils/appender.d | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/utils/appender.d b/utils/appender.d index d4bc927a..7735c6ec 100644 --- a/utils/appender.d +++ b/utils/appender.d @@ -82,8 +82,9 @@ private: } newStart[0..size] = start[0..size]; - if (unique) - allocator.deallocate(start[0..capacity]); + static if (hasMember!(Allocator, "deallocate")) + if (unique) + allocator.deallocate(start[0..capacity]); start = newStart; cursor = start + size; end = start + newCapacity; @@ -117,8 +118,9 @@ public: ~this() { - if (cursor && unique) - allocator.deallocate(start[0..end-start]); + static if (hasMember!(Allocator, "deallocate")) + if (cursor && unique) + allocator.deallocate(start[0..end-start]); } /// Put elements. @@ -312,6 +314,21 @@ unittest } } +unittest +{ + static struct MinimalAllocator + { + static MinimalAllocator instance; + + void[] allocate(size_t size) + { + return new void[](size); + } + } + + alias Test = FastAppender!(int, MinimalAllocator); +} + /// UFCS shim for classic output ranges, which only take a single-argument put. void putEx(R, U...)(auto ref R r, U items) {