diff --git a/dub.selections.json b/dub.selections.json new file mode 100644 index 0000000..012f600 --- /dev/null +++ b/dub.selections.json @@ -0,0 +1,6 @@ +{ + "fileVersion": 1, + "versions": { + "mir-core": "0.0.0" + } +} diff --git a/source/stdx/allocator/building_blocks/affix_allocator.d b/source/stdx/allocator/building_blocks/affix_allocator.d index 9010635..747088f 100644 --- a/source/stdx/allocator/building_blocks/affix_allocator.d +++ b/source/stdx/allocator/building_blocks/affix_allocator.d @@ -26,7 +26,6 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) roundUpToMultipleOf, alignedAt, alignDownTo, roundUpToMultipleOf, hasStaticallyKnownAlignment; import stdx.allocator.internal : isPowerOf2; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; static if (hasStaticallyKnownAlignment!Allocator) @@ -162,7 +161,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) return result[stateSize!Prefix .. stateSize!Prefix + bytes]; } - static if (hasMember!(Allocator, "allocateAll")) + static if (__traits(hasMember, Allocator, "allocateAll")) void[] allocateAll() { auto result = parent.allocateAll(); @@ -191,14 +190,14 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) return result; } - static if (hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "owns")) Ternary owns(void[] b) { if (b is null) return Ternary.no; return parent.owns(actualAllocation(b)); } - static if (hasMember!(Allocator, "resolveInternalPointer")) + static if (__traits(hasMember, Allocator, "resolveInternalPointer")) Ternary resolveInternalPointer(const void* p, ref void[] result) { void[] p1; @@ -212,7 +211,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) return Ternary.yes; } - static if (!stateSize!Suffix && hasMember!(Allocator, "expand")) + static if (!stateSize!Suffix && __traits(hasMember, Allocator, "expand")) bool expand(ref void[] b, size_t delta) { if (!b.ptr) return delta == 0; @@ -223,7 +222,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) return true; } - static if (hasMember!(Allocator, "reallocate")) + static if (__traits(hasMember, Allocator, "reallocate")) bool reallocate(ref void[] b, size_t s) { if (b is null) @@ -238,7 +237,7 @@ struct AffixAllocator(Allocator, Prefix, Suffix = void) return true; } - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) bool deallocate(void[] b) { if (!b.ptr) return true; diff --git a/source/stdx/allocator/building_blocks/allocator_list.d b/source/stdx/allocator/building_blocks/allocator_list.d index ad8f6bd..209d048 100644 --- a/source/stdx/allocator/building_blocks/allocator_list.d +++ b/source/stdx/allocator/building_blocks/allocator_list.d @@ -67,7 +67,6 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) import stdx.allocator.internal : emplace; import stdx.allocator.building_blocks.stats_collector : StatsCollector, Options; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; private enum ouroboros = is(BookkeepingAllocator == NullAllocator); @@ -142,8 +141,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) factory = plant; } - static if (hasMember!(Allocator, "deallocateAll") - && hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "deallocateAll") + && __traits(hasMember, Allocator, "owns")) ~this() { deallocateAll; @@ -236,8 +235,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) // Free the olden buffer static if (ouroboros) { - static if (hasMember!(Allocator, "deallocate") - && hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "deallocate") + && __traits(hasMember, Allocator, "owns")) deallocate(toFree); } else @@ -250,8 +249,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) private Node* addAllocator(size_t atLeastBytes) { void[] t = allocators; - static if (hasMember!(Allocator, "expand") - && hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "expand") + && __traits(hasMember, Allocator, "owns")) { immutable bool expanded = t && this.expand(t, Node.sizeof); } @@ -303,7 +302,7 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) private Node* addAllocator(size_t atLeastBytes) { void[] t = allocators; - static if (hasMember!(BookkeepingAllocator, "expand")) + static if (__traits(hasMember, BookkeepingAllocator, "expand")) immutable bool expanded = bkalloc.expand(t, Node.sizeof); else immutable bool expanded = false; @@ -348,7 +347,7 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) `Ternary.unknown` if no allocator returned `Ternary.yes` and at least one returned `Ternary.unknown`. */ - static if (hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "owns")) Ternary owns(void[] b) { auto result = Ternary.no; @@ -377,8 +376,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) and calls $(D expand) for it. The owner is not brought to the head of the list. */ - static if (hasMember!(Allocator, "expand") - && hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "expand") + && __traits(hasMember, Allocator, "owns")) bool expand(ref void[] b, size_t delta) { if (!b.ptr) return delta == 0; @@ -394,7 +393,7 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) $(D b) and calls $(D reallocate) for it. If that fails, calls the global $(D reallocate), which allocates a new block and moves memory. */ - static if (hasMember!(Allocator, "reallocate")) + static if (__traits(hasMember, Allocator, "reallocate")) bool reallocate(ref void[] b, size_t s) { // First attempt to reallocate within the existing node @@ -414,8 +413,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) /** Defined if $(D Allocator.deallocate) and $(D Allocator.owns) are defined. */ - static if (hasMember!(Allocator, "deallocate") - && hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "deallocate") + && __traits(hasMember, Allocator, "owns")) bool deallocate(void[] b) { if (!b.ptr) return true; @@ -457,8 +456,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) Defined only if $(D Allocator.owns) and $(D Allocator.deallocateAll) are defined. */ - static if (ouroboros && hasMember!(Allocator, "deallocateAll") - && hasMember!(Allocator, "owns")) + static if (ouroboros && __traits(hasMember, Allocator, "deallocateAll") + && __traits(hasMember, Allocator, "owns")) bool deallocateAll() { Node* special; @@ -483,8 +482,8 @@ struct AllocatorList(Factory, BookkeepingAllocator = GCAllocator) return true; } - static if (!ouroboros && hasMember!(Allocator, "deallocateAll") - && hasMember!(Allocator, "owns")) + static if (!ouroboros && __traits(hasMember, Allocator, "deallocateAll") + && __traits(hasMember, Allocator, "owns")) bool deallocateAll() { foreach (ref n; allocators) diff --git a/source/stdx/allocator/building_blocks/bitmapped_block.d b/source/stdx/allocator/building_blocks/bitmapped_block.d index b3ec260..1d9ca38 100644 --- a/source/stdx/allocator/building_blocks/bitmapped_block.d +++ b/source/stdx/allocator/building_blocks/bitmapped_block.d @@ -45,7 +45,6 @@ block size to the constructor. struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment, ParentAllocator = NullAllocator) { - import std.traits : hasMember; import stdx.allocator.internal : Ternary; import std.typecons : tuple, Tuple; @@ -197,7 +196,7 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment deallocate), the destructor is defined to deallocate the block held. */ static if (!is(ParentAllocator == NullAllocator) - && hasMember!(ParentAllocator, "deallocate")) + && __traits(hasMember, ParentAllocator, "deallocate")) ~this() { auto start = _control.rep.ptr, end = cast(ulong*)(_payload.ptr + _payload.length); @@ -691,10 +690,9 @@ struct BitmappedBlock(size_t theBlockSize, uint theAlignment = platformAlignment { // Create a block allocator on top of a 10KB stack region. import stdx.allocator.building_blocks.region : InSituRegion; - import std.traits : hasMember; InSituRegion!(10_240, 64) r; auto a = BitmappedBlock!(64, 64)(cast(ubyte[])(r.allocateAll())); - static assert(hasMember!(InSituRegion!(10_240, 64), "allocateAll")); + static assert(__traits(hasMember, InSituRegion!(10_240, 64), "allocateAll")); const b = a.allocate(100); assert(b.length == 100); } diff --git a/source/stdx/allocator/building_blocks/bucketizer.d b/source/stdx/allocator/building_blocks/bucketizer.d index 1629d36..c524a52 100644 --- a/source/stdx/allocator/building_blocks/bucketizer.d +++ b/source/stdx/allocator/building_blocks/bucketizer.d @@ -18,7 +18,6 @@ for $(D Bucketizer). To handle them separately, $(D Segregator) may be of use. struct Bucketizer(Allocator, size_t min, size_t max, size_t step) { import common = stdx.allocator.common : roundUpToMultipleOf; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; static assert((max - (min - 1)) % step == 0, @@ -72,7 +71,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) Directs the call to either one of the $(D buckets) allocators. Defined only if `Allocator` defines `alignedAllocate`. */ - static if (hasMember!(Allocator, "alignedAllocate")) + static if (__traits(hasMember, Allocator, "alignedAllocate")) void[] alignedAllocate(size_t bytes, uint a) { if (!bytes) return null; @@ -133,7 +132,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) Similar to `reallocate`, with alignment. Defined only if `Allocator` defines `alignedReallocate`. */ - static if (hasMember!(Allocator, "alignedReallocate")) + static if (__traits(hasMember, Allocator, "alignedReallocate")) bool alignedReallocate(ref void[] b, size_t size, uint a) { if (size == 0) @@ -159,7 +158,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) /** Defined only if `Allocator` defines `owns`. Finds the owner of `b` and forwards the call to it. */ - static if (hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "owns")) Ternary owns(void[] b) { if (!b.ptr) return Ternary.no; @@ -174,7 +173,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) /** This method is only defined if $(D Allocator) defines $(D deallocate). */ - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) bool deallocate(void[] b) { if (!b.ptr) return true; @@ -190,7 +189,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) deallocateAll), and calls it for each bucket in turn. Returns `true` if all allocators could deallocate all. */ - static if (hasMember!(Allocator, "deallocateAll")) + static if (__traits(hasMember, Allocator, "deallocateAll")) bool deallocateAll() { bool result = true; @@ -205,7 +204,7 @@ struct Bucketizer(Allocator, size_t min, size_t max, size_t step) This method is only defined if all allocators involved define $(D resolveInternalPointer), and tries it for each bucket in turn. */ - static if (hasMember!(Allocator, "resolveInternalPointer")) + static if (__traits(hasMember, Allocator, "resolveInternalPointer")) Ternary resolveInternalPointer(const void* p, ref void[] result) { foreach (ref a; buckets) diff --git a/source/stdx/allocator/building_blocks/fallback_allocator.d b/source/stdx/allocator/building_blocks/fallback_allocator.d index 88cb98c..ffd4457 100644 --- a/source/stdx/allocator/building_blocks/fallback_allocator.d +++ b/source/stdx/allocator/building_blocks/fallback_allocator.d @@ -21,7 +21,6 @@ up by the $(D GCAllocator). struct FallbackAllocator(Primary, Fallback) { import mir.utility : min; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; @system unittest @@ -65,16 +64,16 @@ struct FallbackAllocator(Primary, Fallback) $(D FallbackAllocator) offers $(D alignedAllocate) iff at least one of the allocators also offers it. It attempts to allocate using either or both. */ - static if (hasMember!(Primary, "alignedAllocate") - || hasMember!(Fallback, "alignedAllocate")) + static if (__traits(hasMember, Primary, "alignedAllocate") + || __traits(hasMember, Fallback, "alignedAllocate")) void[] alignedAllocate(size_t s, uint a) { - static if (hasMember!(Primary, "alignedAllocate")) + static if (__traits(hasMember, Primary, "alignedAllocate")) {{ auto result = primary.alignedAllocate(s, a); if (result.length == s) return result; }} - static if (hasMember!(Fallback, "alignedAllocate")) + static if (__traits(hasMember, Fallback, "alignedAllocate")) {{ auto result = fallback.alignedAllocate(s, a); if (result.length == s) return result; @@ -92,20 +91,20 @@ struct FallbackAllocator(Primary, Fallback) (returning $(D false)) otherwise. */ - static if (hasMember!(Primary, "owns") - && (hasMember!(Primary, "expand") || hasMember!(Fallback, "expand"))) + static if (__traits(hasMember, Primary, "owns") + && (__traits(hasMember, Primary, "expand") || __traits(hasMember, Fallback, "expand"))) bool expand(ref void[] b, size_t delta) { if (!delta) return true; if (!b.ptr) return false; if (primary.owns(b) == Ternary.yes) { - static if (hasMember!(Primary, "expand")) + static if (__traits(hasMember, Primary, "expand")) return primary.expand(b, delta); else return false; } - static if (hasMember!(Fallback, "expand")) + static if (__traits(hasMember, Fallback, "expand")) return fallback.expand(b, delta); else return false; @@ -122,7 +121,7 @@ struct FallbackAllocator(Primary, Fallback) allocation from $(D fallback) to $(D primary). */ - static if (hasMember!(Primary, "owns")) + static if (__traits(hasMember, Primary, "owns")) bool reallocate(ref void[] b, size_t newSize) { bool crossAllocatorMove(From, To)(auto ref From from, auto ref To to) @@ -131,7 +130,7 @@ struct FallbackAllocator(Primary, Fallback) if (b1.length != newSize) return false; if (b.length < newSize) b1[0 .. b.length] = b[]; else b1[] = b[0 .. newSize]; - static if (hasMember!(From, "deallocate")) + static if (__traits(hasMember, From, "deallocate")) from.deallocate(b); b = b1; return true; @@ -148,14 +147,14 @@ struct FallbackAllocator(Primary, Fallback) || crossAllocatorMove(fallback, primary); } - static if (hasMember!(Primary, "owns") - && (hasMember!(Primary, "alignedAllocate") - || hasMember!(Fallback, "alignedAllocate"))) + static if (__traits(hasMember, Primary, "owns") + && (__traits(hasMember, Primary, "alignedAllocate") + || __traits(hasMember, Fallback, "alignedAllocate"))) bool alignedReallocate(ref void[] b, size_t newSize, uint a) { bool crossAllocatorMove(From, To)(auto ref From from, auto ref To to) { - static if (!hasMember!(To, "alignedAllocate")) + static if (!__traits(hasMember, To, "alignedAllocate")) { return false; } @@ -165,14 +164,14 @@ struct FallbackAllocator(Primary, Fallback) if (b1.length != newSize) return false; if (b.length < newSize) b1[0 .. b.length] = b[]; else b1[] = b[0 .. newSize]; - static if (hasMember!(From, "deallocate")) + static if (__traits(hasMember, From, "deallocate")) from.deallocate(b); b = b1; return true; } } - static if (hasMember!(Primary, "alignedAllocate")) + static if (__traits(hasMember, Primary, "alignedAllocate")) { if (b is null || primary.owns(b) == Ternary.yes) { @@ -180,7 +179,7 @@ struct FallbackAllocator(Primary, Fallback) || crossAllocatorMove(primary, fallback); } } - static if (hasMember!(Fallback, "alignedAllocate")) + static if (__traits(hasMember, Fallback, "alignedAllocate")) { return fallback.alignedReallocate(b, newSize, a) || crossAllocatorMove(fallback, primary); @@ -195,7 +194,7 @@ struct FallbackAllocator(Primary, Fallback) $(D owns) is defined if and only if both allocators define $(D owns). Returns $(D primary.owns(b) | fallback.owns(b)). */ - static if (hasMember!(Primary, "owns") && hasMember!(Fallback, "owns")) + static if (__traits(hasMember, Primary, "owns") && __traits(hasMember, Fallback, "owns")) Ternary owns(void[] b) { return primary.owns(b) | fallback.owns(b); @@ -205,8 +204,8 @@ struct FallbackAllocator(Primary, Fallback) $(D resolveInternalPointer) is defined if and only if both allocators define it. */ - static if (hasMember!(Primary, "resolveInternalPointer") - && hasMember!(Fallback, "resolveInternalPointer")) + static if (__traits(hasMember, Primary, "resolveInternalPointer") + && __traits(hasMember, Fallback, "resolveInternalPointer")) Ternary resolveInternalPointer(const void* p, ref void[] result) { Ternary r = primary.resolveInternalPointer(p, result); @@ -221,21 +220,21 @@ struct FallbackAllocator(Primary, Fallback) request is forwarded to $(D fallback.deallocate) if it is defined, or is a no-op otherwise. */ - static if (hasMember!(Primary, "owns") && - (hasMember!(Primary, "deallocate") - || hasMember!(Fallback, "deallocate"))) + static if (__traits(hasMember, Primary, "owns") && + (__traits(hasMember, Primary, "deallocate") + || __traits(hasMember, Fallback, "deallocate"))) bool deallocate(void[] b) { if (primary.owns(b) == Ternary.yes) { - static if (hasMember!(Primary, "deallocate")) + static if (__traits(hasMember, Primary, "deallocate")) return primary.deallocate(b); else return false; } else { - static if (hasMember!(Fallback, "deallocate")) + static if (__traits(hasMember, Fallback, "deallocate")) return fallback.deallocate(b); else return false; @@ -247,7 +246,7 @@ struct FallbackAllocator(Primary, Fallback) Returns: $(D primary.empty & fallback.empty) */ - static if (hasMember!(Primary, "empty") && hasMember!(Fallback, "empty")) + static if (__traits(hasMember, Primary, "empty") && __traits(hasMember, Fallback, "empty")) Ternary empty() { return primary.empty & fallback.empty; diff --git a/source/stdx/allocator/building_blocks/free_list.d b/source/stdx/allocator/building_blocks/free_list.d index b522c48..a2ac420 100644 --- a/source/stdx/allocator/building_blocks/free_list.d +++ b/source/stdx/allocator/building_blocks/free_list.d @@ -29,7 +29,6 @@ struct FreeList(ParentAllocator, Flag!"adaptive" adaptive = No.adaptive) { import std.exception : enforce; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; static assert(minSize != unbounded, "Use minSize = 0 for no low bound."); @@ -351,7 +350,7 @@ struct FreeList(ParentAllocator, root.next = t; return true; } - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) return parent.deallocate(block); else return false; @@ -361,7 +360,7 @@ struct FreeList(ParentAllocator, Defined only if $(D ParentAllocator) defines $(D deallocateAll). If so, forwards to it and resets the freelist. */ - static if (hasMember!(ParentAllocator, "deallocateAll")) + static if (__traits(hasMember, ParentAllocator, "deallocateAll")) bool deallocateAll() { root = null; @@ -373,7 +372,7 @@ struct FreeList(ParentAllocator, freeing each element in turn. Defined only if $(D ParentAllocator) defines $(D deallocate). */ - static if (hasMember!(ParentAllocator, "deallocate") && !unchecked) + static if (__traits(hasMember, ParentAllocator, "deallocate") && !unchecked) void minimize() { while (root) @@ -426,7 +425,6 @@ struct ContiguousFreeList(ParentAllocator, : NullAllocator; import stdx.allocator.building_blocks.stats_collector : StatsCollector, Options; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; alias Impl = FreeList!(NullAllocator, minSize, maxSize); @@ -607,7 +605,7 @@ struct ContiguousFreeList(ParentAllocator, Defined if `ParentAllocator` defines it. Checks whether the block belongs to this allocator. */ - static if (hasMember!(SParent, "owns") || unchecked) + static if (__traits(hasMember, SParent, "owns") || unchecked) Ternary owns(void[] b) { if (support.ptr <= b.ptr && b.ptr < support.ptr + support.length) @@ -645,7 +643,7 @@ struct ContiguousFreeList(ParentAllocator, /** Deallocates everything from the parent. */ - static if (hasMember!(ParentAllocator, "deallocateAll") + static if (__traits(hasMember, ParentAllocator, "deallocateAll") && stateSize!ParentAllocator) bool deallocateAll() { @@ -751,7 +749,6 @@ struct SharedFreeList(ParentAllocator, size_t minSize, size_t maxSize = minSize, size_t approxMaxNodes = unbounded) { import std.exception : enforce; - import std.traits : hasMember; static assert(approxMaxNodes, "approxMaxNodes must not be null."); static assert(minSize != unbounded, "Use minSize = 0 for no low bound."); @@ -925,14 +922,14 @@ struct SharedFreeList(ParentAllocator, } /// Ditto - static if (hasMember!(ParentAllocator, "owns")) + static if (__traits(hasMember, ParentAllocator, "owns")) Ternary owns(void[] b) shared const { return parent.owns(b); } /// Ditto - static if (hasMember!(ParentAllocator, "reallocate")) + static if (__traits(hasMember, ParentAllocator, "reallocate")) bool reallocate(ref void[] b, size_t s) shared { return parent.reallocate(b, s); @@ -981,7 +978,7 @@ struct SharedFreeList(ParentAllocator, lock.unlock(); return true; } - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) return parent.deallocate(b); else return false; @@ -993,11 +990,11 @@ struct SharedFreeList(ParentAllocator, bool result = false; lock.lock(); scope(exit) lock.unlock(); - static if (hasMember!(ParentAllocator, "deallocateAll")) + static if (__traits(hasMember, ParentAllocator, "deallocateAll")) { result = parent.deallocateAll(); } - else static if (hasMember!(ParentAllocator, "deallocate")) + else static if (__traits(hasMember, ParentAllocator, "deallocate")) { result = true; for (auto n = _root; n;) @@ -1018,7 +1015,7 @@ struct SharedFreeList(ParentAllocator, freeing each element in turn. Defined only if $(D ParentAllocator) defines $(D deallocate). */ - static if (hasMember!(ParentAllocator, "deallocate") && !unchecked) + static if (__traits(hasMember, ParentAllocator, "deallocate") && !unchecked) void minimize() shared { lock.lock(); diff --git a/source/stdx/allocator/building_blocks/free_tree.d b/source/stdx/allocator/building_blocks/free_tree.d index 6c98ffe..1171b24 100644 --- a/source/stdx/allocator/building_blocks/free_tree.d +++ b/source/stdx/allocator/building_blocks/free_tree.d @@ -224,7 +224,7 @@ struct FreeTree(ParentAllocator) The destructor of $(D FreeTree) releases all memory back to the parent allocator. */ - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) ~this() { clear; @@ -272,7 +272,7 @@ struct FreeTree(ParentAllocator) if (result.ptr) return result.ptr[0 .. n]; // Parent ran out of juice, desperation mode on - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) { clear; // Try parent allocator again. @@ -327,7 +327,7 @@ struct FreeTree(ParentAllocator) /** Defined if $(D ParentAllocator.deallocate) exists, and returns to it all memory held in the free tree. */ - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) void clear() { void recurse(Node* n) @@ -348,7 +348,7 @@ struct FreeTree(ParentAllocator) stil managed by the free tree). */ - static if (hasMember!(ParentAllocator, "deallocateAll")) + static if (__traits(hasMember, ParentAllocator, "deallocateAll")) bool deallocateAll() { // This is easy, just nuke the root and deallocate all from the diff --git a/source/stdx/allocator/building_blocks/kernighan_ritchie.d b/source/stdx/allocator/building_blocks/kernighan_ritchie.d index 8c9b9dc..225bed5 100644 --- a/source/stdx/allocator/building_blocks/kernighan_ritchie.d +++ b/source/stdx/allocator/building_blocks/kernighan_ritchie.d @@ -96,7 +96,6 @@ information is available in client code at deallocation time.) struct KRRegion(ParentAllocator = NullAllocator) { import stdx.allocator.common : stateSize, alignedAt; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; private static struct Node @@ -343,7 +342,7 @@ struct KRRegion(ParentAllocator = NullAllocator) /// Ditto static if (!is(ParentAllocator == NullAllocator) - && hasMember!(ParentAllocator, "deallocate")) + && __traits(hasMember, ParentAllocator, "deallocate")) ~this() { parent.deallocate(payload); diff --git a/source/stdx/allocator/building_blocks/quantizer.d b/source/stdx/allocator/building_blocks/quantizer.d index 5b2798d..64821f0 100644 --- a/source/stdx/allocator/building_blocks/quantizer.d +++ b/source/stdx/allocator/building_blocks/quantizer.d @@ -36,7 +36,6 @@ value for a given $(D n).) */ struct Quantizer(ParentAllocator, alias roundingFunction) { - import std.traits : hasMember; /** The parent allocator. Depending on whether $(D ParentAllocator) holds state @@ -84,7 +83,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction) $(D allocate) by forwarding to $(D parent.alignedAllocate(goodAllocSize(n), a)). */ - static if (hasMember!(ParentAllocator, "alignedAllocate")) + static if (__traits(hasMember, ParentAllocator, "alignedAllocate")) void[] alignedAllocate(size_t n, uint) { auto result = parent.alignedAllocate(goodAllocSize(n)); @@ -114,7 +113,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction) return true; } // Hail Mary - static if (hasMember!(ParentAllocator, "expand")) + static if (__traits(hasMember, ParentAllocator, "expand")) { // Expand to the appropriate quantum auto original = b.ptr[0 .. allocated]; @@ -166,7 +165,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction) occurs in place under the conditions required by $(D expand). Shrinking occurs in place if $(D goodAllocSize(b.length) == goodAllocSize(s)). */ - static if (hasMember!(ParentAllocator, "alignedAllocate")) + static if (__traits(hasMember, ParentAllocator, "alignedAllocate")) bool alignedReallocate(ref void[] b, size_t s, uint a) { if (!b.ptr) @@ -196,7 +195,7 @@ struct Quantizer(ParentAllocator, alias roundingFunction) Defined if $(D ParentAllocator.deallocate) exists and forwards to $(D parent.deallocate(b.ptr[0 .. goodAllocSize(b.length)])). */ - static if (hasMember!(ParentAllocator, "deallocate")) + static if (__traits(hasMember, ParentAllocator, "deallocate")) bool deallocate(void[] b) { if (!b.ptr) return true; diff --git a/source/stdx/allocator/building_blocks/region.d b/source/stdx/allocator/building_blocks/region.d index 08d6d04..018d3ea 100644 --- a/source/stdx/allocator/building_blocks/region.d +++ b/source/stdx/allocator/building_blocks/region.d @@ -33,7 +33,6 @@ struct Region(ParentAllocator = NullAllocator, static assert(minAlign.isGoodStaticAlignment); static assert(ParentAllocator.alignment >= minAlign); - import std.traits : hasMember; import stdx.allocator.internal : Ternary; // state @@ -98,7 +97,7 @@ struct Region(ParentAllocator = NullAllocator, memory chunk. */ static if (!is(ParentAllocator == NullAllocator) - && hasMember!(ParentAllocator, "deallocate")) + && __traits(hasMember, ParentAllocator, "deallocate")) ~this() { parent.deallocate(_begin[0 .. _end - _begin]); @@ -491,7 +490,7 @@ struct InSituRegion(size_t size, size_t minAlign = platformAlignment) Expands an allocated block in place. Expansion will succeed only if the block is the last allocated. */ - static if (hasMember!(typeof(_impl), "expand")) + static if (__traits(hasMember, typeof(_impl), "expand")) bool expand(ref void[] b, size_t delta) { if (!_impl._current) lazyInit; diff --git a/source/stdx/allocator/building_blocks/scoped_allocator.d b/source/stdx/allocator/building_blocks/scoped_allocator.d index 34c5976..1fc967e 100644 --- a/source/stdx/allocator/building_blocks/scoped_allocator.d +++ b/source/stdx/allocator/building_blocks/scoped_allocator.d @@ -24,7 +24,6 @@ struct ScopedAllocator(ParentAllocator) import stdx.allocator.building_blocks.affix_allocator : AffixAllocator; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; private struct Node @@ -98,7 +97,7 @@ struct ScopedAllocator(ParentAllocator) /** Forwards to $(D parent.expand(b, delta)). */ - static if (hasMember!(Allocator, "expand")) + static if (__traits(hasMember, Allocator, "expand")) bool expand(ref void[] b, size_t delta) { auto result = parent.expand(b, delta); @@ -139,7 +138,7 @@ struct ScopedAllocator(ParentAllocator) /** Forwards to $(D parent.owns(b)). */ - static if (hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "owns")) Ternary owns(void[] b) { return parent.owns(b); @@ -148,7 +147,7 @@ struct ScopedAllocator(ParentAllocator) /** Deallocates $(D b). */ - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) bool deallocate(void[] b) { // Remove from list diff --git a/source/stdx/allocator/building_blocks/segregator.d b/source/stdx/allocator/building_blocks/segregator.d index fa90287..361f3bf 100644 --- a/source/stdx/allocator/building_blocks/segregator.d +++ b/source/stdx/allocator/building_blocks/segregator.d @@ -15,7 +15,6 @@ shared) methods. struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) { import mir.utility : min; - import std.traits : hasMember; import stdx.allocator.internal : Ternary; static if (stateSize!SmallAllocator) private SmallAllocator _small; @@ -139,8 +138,8 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) return s <= threshold ? _small.allocate(s) : _large.allocate(s); } - static if (hasMember!(SmallAllocator, "alignedAllocate") - && hasMember!(LargeAllocator, "alignedAllocate")) + static if (__traits(hasMember, SmallAllocator, "alignedAllocate") + && __traits(hasMember, LargeAllocator, "alignedAllocate")) void[] alignedAllocate(size_t s, uint a) { return s <= threshold @@ -148,15 +147,15 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) : _large.alignedAllocate(s, a); } - static if (hasMember!(SmallAllocator, "expand") - || hasMember!(LargeAllocator, "expand")) + static if (__traits(hasMember, SmallAllocator, "expand") + || __traits(hasMember, LargeAllocator, "expand")) bool expand(ref void[] b, size_t delta) { if (!delta) return true; if (b.length + delta <= threshold) { // Old and new allocations handled by _small - static if (hasMember!(SmallAllocator, "expand")) + static if (__traits(hasMember, SmallAllocator, "expand")) return _small.expand(b, delta); else return false; @@ -164,7 +163,7 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) if (b.length > threshold) { // Old and new allocations handled by _large - static if (hasMember!(LargeAllocator, "expand")) + static if (__traits(hasMember, LargeAllocator, "expand")) return _large.expand(b, delta); else return false; @@ -173,62 +172,62 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) return false; } - static if (hasMember!(SmallAllocator, "reallocate") - || hasMember!(LargeAllocator, "reallocate")) + static if (__traits(hasMember, SmallAllocator, "reallocate") + || __traits(hasMember, LargeAllocator, "reallocate")) bool reallocate(ref void[] b, size_t s) { - static if (hasMember!(SmallAllocator, "reallocate")) + static if (__traits(hasMember, SmallAllocator, "reallocate")) if (b.length <= threshold && s <= threshold) { // Old and new allocations handled by _small return _small.reallocate(b, s); } - static if (hasMember!(LargeAllocator, "reallocate")) + static if (__traits(hasMember, LargeAllocator, "reallocate")) if (b.length > threshold && s > threshold) { // Old and new allocations handled by _large return _large.reallocate(b, s); } // Cross-allocator transgression - static if (!hasMember!(typeof(this), "instance")) + static if (!__traits(hasMember, typeof(this), "instance")) return .reallocate(this, b, s); else return .reallocate(instance, b, s); } - static if (hasMember!(SmallAllocator, "alignedReallocate") - || hasMember!(LargeAllocator, "alignedReallocate")) + static if (__traits(hasMember, SmallAllocator, "alignedReallocate") + || __traits(hasMember, LargeAllocator, "alignedReallocate")) bool alignedReallocate(ref void[] b, size_t s) { - static if (hasMember!(SmallAllocator, "alignedReallocate")) + static if (__traits(hasMember, SmallAllocator, "alignedReallocate")) if (b.length <= threshold && s <= threshold) { // Old and new allocations handled by _small return _small.alignedReallocate(b, s); } - static if (hasMember!(LargeAllocator, "alignedReallocate")) + static if (__traits(hasMember, LargeAllocator, "alignedReallocate")) if (b.length > threshold && s > threshold) { // Old and new allocations handled by _large return _large.alignedReallocate(b, s); } // Cross-allocator transgression - static if (!hasMember!(typeof(this), "instance")) + static if (!__traits(hasMember, typeof(this), "instance")) return .alignedReallocate(this, b, s); else return .alignedReallocate(instance, b, s); } - static if (hasMember!(SmallAllocator, "owns") - && hasMember!(LargeAllocator, "owns")) + static if (__traits(hasMember, SmallAllocator, "owns") + && __traits(hasMember, LargeAllocator, "owns")) Ternary owns(void[] b) { return Ternary(b.length <= threshold ? _small.owns(b) : _large.owns(b)); } - static if (hasMember!(SmallAllocator, "deallocate") - && hasMember!(LargeAllocator, "deallocate")) + static if (__traits(hasMember, SmallAllocator, "deallocate") + && __traits(hasMember, LargeAllocator, "deallocate")) bool deallocate(void[] data) { return data.length <= threshold @@ -236,23 +235,23 @@ struct Segregator(size_t threshold, SmallAllocator, LargeAllocator) : _large.deallocate(data); } - static if (hasMember!(SmallAllocator, "deallocateAll") - && hasMember!(LargeAllocator, "deallocateAll")) + static if (__traits(hasMember, SmallAllocator, "deallocateAll") + && __traits(hasMember, LargeAllocator, "deallocateAll")) bool deallocateAll() { // Use & insted of && to evaluate both return _small.deallocateAll() & _large.deallocateAll(); } - static if (hasMember!(SmallAllocator, "empty") - && hasMember!(LargeAllocator, "empty")) + static if (__traits(hasMember, SmallAllocator, "empty") + && __traits(hasMember, LargeAllocator, "empty")) Ternary empty() { return _small.empty && _large.empty; } - static if (hasMember!(SmallAllocator, "resolveInternalPointer") - && hasMember!(LargeAllocator, "resolveInternalPointer")) + static if (__traits(hasMember, SmallAllocator, "resolveInternalPointer") + && __traits(hasMember, LargeAllocator, "resolveInternalPointer")) Ternary resolveInternalPointer(const void* p, ref void[] result) { Ternary r = _small.resolveInternalPointer(p, result); diff --git a/source/stdx/allocator/building_blocks/stats_collector.d b/source/stdx/allocator/building_blocks/stats_collector.d index 723c4fa..27f60d2 100644 --- a/source/stdx/allocator/building_blocks/stats_collector.d +++ b/source/stdx/allocator/building_blocks/stats_collector.d @@ -158,7 +158,6 @@ struct StatsCollector(Allocator, ulong flags = Options.all, ulong perCallFlags = 0) { private: - import std.traits : hasMember, Signed; import stdx.allocator.internal : Ternary; static string define(string type, string[] names...) @@ -172,7 +171,7 @@ private: return result; } - void add(string counter)(Signed!size_t n) + void add(string counter)(sizediff_t n) { mixin("static if (flags & Options." ~ counter ~ ") _" ~ counter ~ " += n;"); @@ -283,7 +282,7 @@ public: Increments $(D numOwns) (per instance and and per call) and forwards to $(D parent.owns(b)). */ - static if (hasMember!(Allocator, "owns")) + static if (__traits(hasMember, Allocator, "owns")) { static if ((perCallFlags & Options.numOwns) == 0) Ternary owns(void[] b) @@ -357,8 +356,8 @@ public: private bool expandImpl(string f = null, uint n = 0)(ref void[] b, size_t s) { up!"numExpand"; - Signed!size_t slack = 0; - static if (!hasMember!(Allocator, "expand")) + sizediff_t slack = 0; + static if (!__traits(hasMember, Allocator, "expand")) { auto result = s == 0; } @@ -372,7 +371,7 @@ public: add!"bytesUsed"(s); add!"bytesAllocated"(s); add!"bytesExpanded"(s); - slack = Signed!size_t(this.goodAllocSize(b.length) - b.length + slack = sizediff_t(this.goodAllocSize(b.length) - b.length - bytesSlackB4); add!"bytesSlack"(slack); } @@ -419,16 +418,16 @@ public: const result = parent.reallocate(b, s); - Signed!size_t slack = 0; + sizediff_t slack = 0; bool wasInPlace = false; - Signed!size_t delta = 0; + sizediff_t delta = 0; if (result) { up!"numReallocateOK"; slack = (this.goodAllocSize(b.length) - b.length) - bytesSlackB4; add!"bytesSlack"(slack); - add!"bytesUsed"(Signed!size_t(b.length - oldLength)); + add!"bytesUsed"(sizediff_t(b.length - oldLength)); if (oldB == b.ptr) { // This was an in-place reallocation, yay @@ -480,16 +479,16 @@ public: private bool deallocateImpl(string f = null, uint n = 0)(void[] b) { up!"numDeallocate"; - add!"bytesUsed"(-Signed!size_t(b.length)); + add!"bytesUsed"(-sizediff_t(b.length)); add!"bytesSlack"(-(this.goodAllocSize(b.length) - b.length)); addPerCall!(f, n, "numDeallocate", "bytesContracted")(1, b.length); - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) return parent.deallocate(b); else return false; } - static if (hasMember!(Allocator, "deallocateAll")) + static if (__traits(hasMember, Allocator, "deallocateAll")) { /** Defined only if $(D Allocator.deallocateAll) is defined. Affects diff --git a/source/stdx/allocator/common.d b/source/stdx/allocator/common.d index 567133c..a0f5663 100644 --- a/source/stdx/allocator/common.d +++ b/source/stdx/allocator/common.d @@ -6,7 +6,8 @@ appropriate parts of `std`. Authors: $(HTTP erdani.com, Andrei Alexandrescu), Timon Gehr (`Ternary`) */ module stdx.allocator.common; -import mir.utility, std.traits; +import mir.utility; +import std.traits; /** Returns the size in bytes of the state that needs to be allocated to hold an @@ -350,7 +351,7 @@ implementation of $(D reallocate). bool reallocate(Allocator)(auto ref Allocator a, ref void[] b, size_t s) { if (b.length == s) return true; - static if (hasMember!(Allocator, "expand")) + static if (__traits(hasMember, Allocator, "expand")) { if (b.length <= s && a.expand(b, s - b.length)) return true; } @@ -358,7 +359,7 @@ bool reallocate(Allocator)(auto ref Allocator a, ref void[] b, size_t s) if (newB.length != s) return false; if (newB.length <= b.length) newB[] = b[0 .. newB.length]; else newB[0 .. b.length] = b[]; - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) a.deallocate(b); b = newB; return true; @@ -381,7 +382,7 @@ implementation of $(D reallocate). bool alignedReallocate(Allocator)(auto ref Allocator alloc, ref void[] b, size_t s, uint a) { - static if (hasMember!(Allocator, "expand")) + static if (__traits(hasMember, Allocator, "expand")) { if (b.length <= s && b.ptr.alignedAt(a) && alloc.expand(b, s - b.length)) return true; @@ -393,7 +394,7 @@ bool alignedReallocate(Allocator)(auto ref Allocator alloc, auto newB = alloc.alignedAllocate(s, a); if (newB.length <= b.length) newB[] = b[0 .. newB.length]; else newB[0 .. b.length] = b[]; - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) alloc.deallocate(b); b = newB; return true; @@ -404,11 +405,11 @@ Forwards each of the methods in `funs` (if defined) to `member`. */ /*package*/ string forwardToMember(string member, string[] funs...) { - string result = " import std.traits : hasMember, Parameters;\n"; + string result = " import std.traits : Parameters;\n"; foreach (fun; funs) { result ~= " - static if (hasMember!(typeof("~member~"), `"~fun~"`)) + static if (__traits(hasMember, typeof("~member~"), `"~fun~"`)) { static if (__traits(isTemplate, "~member~"."~fun~")) auto ref "~fun~"(Parameters!(typeof("~member~"."~fun~"!())) args) @@ -459,26 +460,26 @@ version(unittest) assert(b2.ptr + b2.length <= b1.ptr || b1.ptr + b1.length <= b2.ptr); // Test alignedAllocate - static if (hasMember!(A, "alignedAllocate")) + static if (__traits(hasMember, A, "alignedAllocate")) {{ auto b3 = a.alignedAllocate(1, 256); assert(b3.length <= 1); assert(b3.ptr.alignedAt(256)); assert(a.alignedReallocate(b3, 2, 512)); assert(b3.ptr.alignedAt(512)); - static if (hasMember!(A, "alignedDeallocate")) + static if (__traits(hasMember, A, "alignedDeallocate")) { a.alignedDeallocate(b3); } }} else { - static assert(!hasMember!(A, "alignedDeallocate")); + static assert(!__traits(hasMember, A, "alignedDeallocate")); // This seems to be a bug in the compiler: - //static assert(!hasMember!(A, "alignedReallocate"), A.stringof); + //static assert(!__traits(hasMember, A, "alignedReallocate"), A.stringof); } - static if (hasMember!(A, "allocateAll")) + static if (__traits(hasMember, A, "allocateAll")) {{ auto aa = make(); if (aa.allocateAll().ptr) @@ -493,7 +494,7 @@ version(unittest) assert(!ab.allocate(1).ptr); }} - static if (hasMember!(A, "expand")) + static if (__traits(hasMember, A, "expand")) {{ assert(a.expand(b1, 0)); auto len = b1.length; @@ -518,7 +519,7 @@ version(unittest) assert(b6.length == 2); // Test owns - static if (hasMember!(A, "owns")) + static if (__traits(hasMember, A, "owns")) {{ assert(a.owns(null) == Ternary.no); assert(a.owns(b1) == Ternary.yes); @@ -526,7 +527,7 @@ version(unittest) assert(a.owns(b6) == Ternary.yes); }} - static if (hasMember!(A, "resolveInternalPointer")) + static if (__traits(hasMember, A, "resolveInternalPointer")) {{ void[] p; assert(a.resolveInternalPointer(null, p) == Ternary.no); diff --git a/source/stdx/allocator/package.d b/source/stdx/allocator/package.d index a14757f..31c342e 100644 --- a/source/stdx/allocator/package.d +++ b/source/stdx/allocator/package.d @@ -2018,8 +2018,7 @@ if (!isPointer!A) else static if (is(typeof({ A b = a; A c = b; }))) // copyable { auto state = a.allocate(stateSize!(CAllocatorImpl!A)); - import std.traits : hasMember; - static if (hasMember!(A, "deallocate")) + static if (__traits(hasMember, A, "deallocate")) { scope(failure) a.deallocate(state); } @@ -2045,8 +2044,7 @@ CAllocatorImpl!(A, Yes.indirect) allocatorObject(A)(A* pa) assert(pa); import stdx.allocator.internal : emplace; auto state = pa.allocate(stateSize!(CAllocatorImpl!(A, Yes.indirect))); - import std.traits : hasMember; - static if (hasMember!(A, "deallocate")) + static if (__traits(hasMember, A, "deallocate")) { scope(failure) pa.deallocate(state); } @@ -2113,8 +2111,7 @@ if (!isPointer!A) else static if (is(typeof({ shared A b = a; shared A c = b; }))) // copyable { auto state = a.allocate(stateSize!(CSharedAllocatorImpl!A)); - import std.traits : hasMember; - static if (hasMember!(A, "deallocate")) + static if (__traits(hasMember, A, "deallocate")) { scope(failure) a.deallocate(state); } @@ -2132,8 +2129,7 @@ shared(CSharedAllocatorImpl!(A, Yes.indirect)) sharedAllocatorObject(A)(A* pa) assert(pa); import stdx.allocator.internal : emplace; auto state = pa.allocate(stateSize!(CSharedAllocatorImpl!(A, Yes.indirect))); - import std.traits : hasMember; - static if (hasMember!(A, "deallocate")) + static if (__traits(hasMember, A, "deallocate")) { scope(failure) pa.deallocate(state); } @@ -2152,7 +2148,6 @@ Usually `CAllocatorImpl` is used indirectly by calling $(LREF theAllocator). class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) : IAllocator { - import std.traits : hasMember; /** The implementation is available as a public member. @@ -2203,7 +2198,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override void[] alignedAllocate(size_t s, uint a) { - static if (hasMember!(Allocator, "alignedAllocate")) + static if (__traits(hasMember, Allocator, "alignedAllocate")) return impl.alignedAllocate(s, a); else return null; @@ -2215,14 +2210,14 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override Ternary owns(void[] b) { - static if (hasMember!(Allocator, "owns")) return impl.owns(b); + static if (__traits(hasMember, Allocator, "owns")) return impl.owns(b); else return Ternary.unknown; } /// Returns $(D impl.expand(b, s)) if defined, `false` otherwise. override bool expand(ref void[] b, size_t s) { - static if (hasMember!(Allocator, "expand")) + static if (__traits(hasMember, Allocator, "expand")) return impl.expand(b, s); else return s == 0; @@ -2237,7 +2232,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) /// Forwards to `impl.alignedReallocate` if defined, `false` otherwise. bool alignedReallocate(ref void[] b, size_t s, uint a) { - static if (!hasMember!(Allocator, "alignedAllocate")) + static if (!__traits(hasMember, Allocator, "alignedAllocate")) { return false; } @@ -2250,7 +2245,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) // Undocumented for now Ternary resolveInternalPointer(const void* p, ref void[] result) { - static if (hasMember!(Allocator, "resolveInternalPointer")) + static if (__traits(hasMember, Allocator, "resolveInternalPointer")) { return impl.resolveInternalPointer(p, result); } @@ -2266,7 +2261,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override bool deallocate(void[] b) { - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) { return impl.deallocate(b); } @@ -2282,7 +2277,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override bool deallocateAll() { - static if (hasMember!(Allocator, "deallocateAll")) + static if (__traits(hasMember, Allocator, "deallocateAll")) { return impl.deallocateAll(); } @@ -2297,7 +2292,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override Ternary empty() { - static if (hasMember!(Allocator, "empty")) + static if (__traits(hasMember, Allocator, "empty")) { return Ternary(impl.empty); } @@ -2312,7 +2307,7 @@ class CAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override void[] allocateAll() { - static if (hasMember!(Allocator, "allocateAll")) + static if (__traits(hasMember, Allocator, "allocateAll")) { return impl.allocateAll(); } @@ -2335,7 +2330,6 @@ $(LREF processAllocator). class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) : ISharedAllocator { - import std.traits : hasMember; /** The implementation is available as a public member. @@ -2386,7 +2380,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override void[] alignedAllocate(size_t s, uint a) shared { - static if (hasMember!(Allocator, "alignedAllocate")) + static if (__traits(hasMember, Allocator, "alignedAllocate")) return impl.alignedAllocate(s, a); else return null; @@ -2398,14 +2392,14 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override Ternary owns(void[] b) shared { - static if (hasMember!(Allocator, "owns")) return impl.owns(b); + static if (__traits(hasMember, Allocator, "owns")) return impl.owns(b); else return Ternary.unknown; } /// Returns $(D impl.expand(b, s)) if defined, `false` otherwise. override bool expand(ref void[] b, size_t s) shared { - static if (hasMember!(Allocator, "expand")) + static if (__traits(hasMember, Allocator, "expand")) return impl.expand(b, s); else return s == 0; @@ -2420,7 +2414,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) /// Forwards to `impl.alignedReallocate` if defined, `false` otherwise. bool alignedReallocate(ref void[] b, size_t s, uint a) shared { - static if (!hasMember!(Allocator, "alignedAllocate")) + static if (!__traits(hasMember, Allocator, "alignedAllocate")) { return false; } @@ -2433,7 +2427,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) // Undocumented for now Ternary resolveInternalPointer(const void* p, ref void[] result) shared { - static if (hasMember!(Allocator, "resolveInternalPointer")) + static if (__traits(hasMember, Allocator, "resolveInternalPointer")) { return impl.resolveInternalPointer(p, result); } @@ -2449,7 +2443,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override bool deallocate(void[] b) shared { - static if (hasMember!(Allocator, "deallocate")) + static if (__traits(hasMember, Allocator, "deallocate")) { return impl.deallocate(b); } @@ -2465,7 +2459,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override bool deallocateAll() shared { - static if (hasMember!(Allocator, "deallocateAll")) + static if (__traits(hasMember, Allocator, "deallocateAll")) { return impl.deallocateAll(); } @@ -2480,7 +2474,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override Ternary empty() shared { - static if (hasMember!(Allocator, "empty")) + static if (__traits(hasMember, Allocator, "empty")) { return Ternary(impl.empty); } @@ -2495,7 +2489,7 @@ class CSharedAllocatorImpl(Allocator, Flag!"indirect" indirect = No.indirect) */ override void[] allocateAll() shared { - static if (hasMember!(Allocator, "allocateAll")) + static if (__traits(hasMember, Allocator, "allocateAll")) { return impl.allocateAll(); } @@ -2588,7 +2582,7 @@ unittest static assert(!is(ThreadLocal!GCAllocator)); alias ThreadLocal!(FreeList!(GCAllocator, 0, 8)) Allocator; auto b = Allocator.instance.allocate(5); - static assert(hasMember!(Allocator, "allocate")); + static assert(__traits(hasMember, Allocator, "allocate")); } /* @@ -2851,7 +2845,7 @@ private struct InternalPointersTree(Allocator) } /// Ditto - static if (hasMember!(Allocator, "reallocate")) + static if (__traits(hasMember, Allocator, "reallocate")) bool reallocate(ref void[] b, size_t s) { auto n = &parent.prefix(b); diff --git a/source/stdx/allocator/showcase.d b/source/stdx/allocator/showcase.d index 03e02f7..acc0b34 100644 --- a/source/stdx/allocator/showcase.d +++ b/source/stdx/allocator/showcase.d @@ -10,7 +10,6 @@ module stdx.allocator.showcase; import stdx.allocator.building_blocks.fallback_allocator, stdx.allocator.gc_allocator, stdx.allocator.building_blocks.region; -import std.traits : hasMember; /** @@ -21,7 +20,7 @@ then falls back to $(D Allocator). Defined as: alias StackFront(size_t stackSize, Allocator) = FallbackAllocator!( InSituRegion!(stackSize, Allocator.alignment, - hasMember!(Allocator, "deallocate") + __traits(hasMember, Allocator, "deallocate") ? Yes.defineDeallocate : No.defineDeallocate), Allocator); diff --git a/source/stdx/allocator/typed.d b/source/stdx/allocator/typed.d index bcd28d1..202a4f5 100644 --- a/source/stdx/allocator/typed.d +++ b/source/stdx/allocator/typed.d @@ -13,9 +13,8 @@ module stdx.allocator.typed; import stdx.allocator; import stdx.allocator.common; -import std.range : isInputRange, isForwardRange, walkLength, save, empty, +import std.range.primitives : isInputRange, isForwardRange, save, empty, front, popFront; -import std.traits : isPointer, hasElaborateDestructor; import std.typecons : Flag, Yes, No; /**