File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
std/experimental/allocator Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,39 @@ unittest
6666 static assert (stateSize! C3 == 2 * size_t .sizeof + char .sizeof);
6767}
6868
69+ /**
70+ State of an allocator `A`.
71+
72+ `AllocatorState!(A).sizeof` is zero for `A` being `NullAllocator`, `Mallocator`,
73+ `GCAllocator`, and `MMapAllocator` and typically non-zero for the other.
74+ */
75+ mixin template AllocatorState(A)
76+ if (isAllocator! A)
77+ {
78+ static if (stateSize! A == 0 )
79+ alias allocator = A.instance;
80+ else
81+ A allocator;
82+ }
83+
84+ // /
85+ @safe @nogc nothrow pure
86+ unittest
87+ {
88+ import std.experimental.allocator.building_blocks.null_allocator : NullAllocator;
89+ import std.experimental.allocator.mallocator : Mallocator;
90+ import std.experimental.allocator.gc_allocator : GCAllocator;
91+ import std.experimental.allocator.mmap_allocator : MmapAllocator;
92+ struct S
93+ {
94+ mixin AllocatorState! NullAllocator n;
95+ mixin AllocatorState! GCAllocator g;
96+ mixin AllocatorState! Mallocator m;
97+ mixin AllocatorState! MmapAllocator p;
98+ }
99+ static assert (S.sizeof == 1 );
100+ }
101+
69102/**
70103Returns `true` if the `Allocator` has the alignment known at compile time;
71104otherwise it returns `false`.
You can’t perform that action at this time.
0 commit comments