digitalmars.D.learn - Absence of isAllocator trait
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/2) Sep 04 2021 Is there a reason for the absence of an `isAllocator` trait under
- Basile B. (8/10) Sep 06 2021 I had ask a similar Q once and I've been told that (more or less):
- Paul Backus (10/15) Sep 06 2021 According to [the documentation][1], there are two required
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (9/10) Sep 06 2021 Should be
Is there a reason for the absence of an `isAllocator` trait under `std.experimental.allocator`?
Sep 04 2021
On Saturday, 4 September 2021 at 19:43:27 UTC, Per Nordlöw wrote:Is there a reason for the absence of an `isAllocator` trait under `std.experimental.allocator`?I had ask a similar Q once and I've been told that (more or less): It's because the clients of an allocator should rather statically check for specific traits of an allocator, there are too many possible permutations of capabilities possible, not all can allocate and deallocate, not all can reallocate, and so on. actually I'm 100% sure that what you want is `isMallocator` and not `isAllocator` ;)
Sep 06 2021
On Monday, 6 September 2021 at 13:24:56 UTC, Basile B. wrote:It's because the clients of an allocator should rather statically check for specific traits of an allocator, there are too many possible permutations of capabilities possible, not all can allocate and deallocate, not all can reallocate, and so on.According to [the documentation][1], there are two required properties all allocators must have: * `uint alignment` * `void allocate(size_t size)` So it makes sense to have an `isAllocator` trait that checks for those, even if clients are expected to check for other properties individually. [1]: https://dlang.org/phobos/std_experimental_allocator_building_blocks.html
Sep 06 2021
On Monday, 6 September 2021 at 15:46:52 UTC, Paul Backus wrote:* `void allocate(size_t size)`Should be * `void[] allocate(size_t size)` Thanks. Here's what I have so far ```d enum isAllocator(T) = (is(typeof(T.allocate(size_t.init)) == void[]) && is(typeof(T.alignment) == uint)); ```
Sep 06 2021