@safe containers with std.experimental.allocator
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jan 21 07:35:04 PST 2017
On Sat, 21 Jan 2017 04:01:06 +0000, bitwise wrote:
> On Saturday, 21 January 2017 at 02:47:49 UTC, bitwise wrote:
>> [...]
>
> I can see that 'TypedAllocator' exists, but with a different interface
> than the rest of the allocators. Why wouldn't all allocators just have a
> common interface?
TypedAllocator combines several allocators, using a series of Policies to
determine which one to use for a given type.
The interface for allocators is mostly given by IAllocator and mostly
implemented with UFCS functions defined in
std.experimental.allocator.package. The one aspect that isn't given with
IAllocator (because OOP doesn't support it well) is that not all
allocators have to support aligned allocations.
TypedAllocator overrides some of those default implementations in order
to use its Policies. It doesn't expose the untyped variants so that you
can't get around its Policies.
Unfortunately, there's no way to require that a TypedAllocator return an
aligned allocation aside from using an aligned allocator for the relevant
policy.
More information about the Digitalmars-d
mailing list