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

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 3 05:34:02 PDT 2016


On Friday, June 03, 2016 14:01:57 Dicebot via Digitalmars-d wrote:
> 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.

Presumably, what he wants is the equivalent of std.array.uninitializedArray
but with allocators. It's not the sort of thing that I'd recommend doing
normally, since you're at a high risk of shooting yourself in the foot, but
it should be possible.

Actually, it's stuff like that and emplace that makes invariants pretty much
useless, since opAssign checks the invariant before it's called, meaning
that you end up with garbage being checked against the invariant before you
give it a proper value. Unfortunately, I couldn't convince Walter that
opAssign should stop checking the invariant. :(

But while stuff like initializing to void should generally be avoided, it
_is_ possible, including with arrays.

- Jonathan M Davis



More information about the Digitalmars-d mailing list