Update how AffixAllocator infers shared from parent

This commit is contained in:
Eduard Staniloiu 2018-02-18 16:19:54 +00:00
parent d9934a88b3
commit b45f25b96b

View file

@ -349,9 +349,15 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
}
else static if (is(typeof(Allocator.instance) == shared))
{
static assert(stateSize!Allocator == 0);
static shared AffixAllocator instance;
shared { mixin Impl!(); }
}
else static if (is(Allocator == shared))
{
static assert(stateSize!Allocator != 0);
shared { mixin Impl!(); }
}
else
{
mixin Impl!();
@ -499,3 +505,18 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
assert(b.length == 100);
assert((() nothrow @nogc => a.deallocate(b))());
}
@system unittest
{
import std.experimental.allocator : processAllocator, RCISharedAllocator;
import std.traits;
alias SharedAllocT = shared AffixAllocator!(RCISharedAllocator, int);
static assert(is(RCISharedAllocator == shared));
static assert(!is(SharedAllocT.instance));
SharedAllocT a = SharedAllocT(processAllocator);
auto buf = a.allocate(10);
static assert(is(typeof(a.allocate) == shared));
assert(buf.length == 10);
}