mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
Update how AffixAllocator infers shared from parent
This commit is contained in:
parent
d9934a88b3
commit
b45f25b96b
1 changed files with 21 additions and 0 deletions
|
@ -349,9 +349,15 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
|
||||||
}
|
}
|
||||||
else static if (is(typeof(Allocator.instance) == shared))
|
else static if (is(typeof(Allocator.instance) == shared))
|
||||||
{
|
{
|
||||||
|
static assert(stateSize!Allocator == 0);
|
||||||
static shared AffixAllocator instance;
|
static shared AffixAllocator instance;
|
||||||
shared { mixin Impl!(); }
|
shared { mixin Impl!(); }
|
||||||
}
|
}
|
||||||
|
else static if (is(Allocator == shared))
|
||||||
|
{
|
||||||
|
static assert(stateSize!Allocator != 0);
|
||||||
|
shared { mixin Impl!(); }
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mixin Impl!();
|
mixin Impl!();
|
||||||
|
@ -499,3 +505,18 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
|
||||||
assert(b.length == 100);
|
assert(b.length == 100);
|
||||||
assert((() nothrow @nogc => a.deallocate(b))());
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue