On Monday, 23 September 2013 at 04:19:34 UTC, Manu wrote:
You've just described C++ verbatim.
And you've previously agreed that C++'s approach totally
failed. Can you
explain how this is different from C++, and how it solves the
issues that
defeated that design?
One possibility I'm keeping in mind is that of defining a
dynamic interface
Once you have static allocator you can go dynamic easily:
interface DynamicAllocator // isAllocator==true
{
// whatever the interface is
}
struct StaticAllocator // isAllocator==true
{
}
struct Container(ALLOCATOR = DynamicAllocator) if
(isAllocator!ALLOCATOR)
{
this(ALLOCATOR a){}
}
class DynamicAllocatorWrapper(T) : DynamicAllocator if (is(T) ==
struct)
{
// wraps any static allocator to be callable using dynamic
interface
}
With that boilerplate you can easily create allocator agnostic
containers:
auto c = Container(new
DynamicAllocatorWrapper!(StaticAllocator)())
and you can create specialized version if you need speed very
much:
auto c = Container!(StaticAllocator)(StaticAllocator());