Skip to content

Commit ec862ff

Browse files
authored
Merge pull request #6194 from edi33416/aff_alloc_shared
Update how AffixAllocator infers shared from parent merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
2 parents 162010b + b45f25b commit ec862ff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

std/experimental/allocator/building_blocks/affix_allocator.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,15 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
349349
}
350350
else static if (is(typeof(Allocator.instance) == shared))
351351
{
352+
static assert(stateSize!Allocator == 0);
352353
static shared AffixAllocator instance;
353354
shared { mixin Impl!(); }
354355
}
356+
else static if (is(Allocator == shared))
357+
{
358+
static assert(stateSize!Allocator != 0);
359+
shared { mixin Impl!(); }
360+
}
355361
else
356362
{
357363
mixin Impl!();
@@ -499,3 +505,18 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void)
499505
assert(b.length == 100);
500506
assert((() nothrow @nogc => a.deallocate(b))());
501507
}
508+
509+
@system unittest
510+
{
511+
import std.experimental.allocator : processAllocator, RCISharedAllocator;
512+
import std.traits;
513+
514+
alias SharedAllocT = shared AffixAllocator!(RCISharedAllocator, int);
515+
static assert(is(RCISharedAllocator == shared));
516+
static assert(!is(SharedAllocT.instance));
517+
518+
SharedAllocT a = SharedAllocT(processAllocator);
519+
auto buf = a.allocate(10);
520+
static assert(is(typeof(a.allocate) == shared));
521+
assert(buf.length == 10);
522+
}

0 commit comments

Comments
 (0)