std.experimental.alloctor does not work with non default constructible types

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 3 05:01:57 PDT 2016


On 06/03/2016 01:47 PM, maik klein wrote:
> I rely a lot on std.experimental.alloctor for my "game engine". I have
> just finished creating my own version for "Algebraic" and I want to
> disable to default construction as it would make no sense.
> 
> I have also created my own containers, the problem is that I can not use
> my version of "Algebraic" in any of my containers because all of them
> are using std.experimental.alloctor.makeArray which can not be used with
> non default constructible types.
> 
> While I don't want to have any default constructed type of Algebraic, I
> really don't care for uninitialized values that I will never use anyway.
> 
> I am sure there is a workaround with unions but it would be nice if
> makeArray/expandArray would just support non default constructible types.
> 
> Thoughts?

Do you refer specifically to `makeArray` family of helpers or something
more than that? Basic allocator interface is untyped and doesn't do any
construction, i.e.
https://dlang.org/phobos/std_experimental_allocator.html#.CAllocatorImpl.allocate
- even plain `make` helper
(https://dlang.org/phobos/std_experimental_allocator.html#.make) accepts
optional list of arguments for non-default construction.

For `makeArray` I don't see how it can possibly be fixed. Lack of
default construction means no valid initial value for array elements,
period. I don't know if you can declare plain static array of such
structs but you shouldn't be able to.

Note that `makeArray` also accepts optional `init` argument to be used
instead of default constructed state.


More information about the Digitalmars-d mailing list