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) {