Maik Klein
Maik Klein

Reputation: 16148

Array with non copyable types

How would I express std::vector<std::unique<foo>> p in D?

Array!(Unique!Foo) p

The problem is that Array seems to require this(this) which has been disabled in Unique. I am not sure why Array requires a postblit constructor in the first place.

Upvotes: 3

Views: 68

Answers (1)

Jonathan M Davis
Jonathan M Davis

Reputation: 38287

As far as I know, nothing in std.container currently supports non-copyable types. The fact that D default initializes everything unless you go to the extra effort of telling it not to makes it much harder in general to support types that can't be assigned to or copied. It's definitely the sort of thing that you have to plan for, or it won't work. And AFAIK, non-copyable types were not considered when std.container was originally designed. In fact, I'm pretty sure that at the time, it wasn't possible to @disable default initialization for a type, and it may not have been possible to @disable the postblit constructor. But I don't recall when exactly @disable was introduced or what it worked on originally.

So, you're talking about doing something that was not originally planned for, and it may or may not be possible to make it work with the current design. Regardless, if it doesn't work, then a bug report should be opened for it: https://issues.dlang.org

Now, it's been the plan for some time now that std.container would get some adjustments when allocators were added to the standard library, and with 2.070, we now have std.experimental.allocator, and Andrei Alexandrescu is currently in the process of doing a major redesign of our container solution such that we're going to end up with a new package/module to handle containers (probably std.collection, since std.container is obviously already taken). So, this is something that should be brought up and resolved with the new container types regardless of whether it ever gets fixed with std.container.

Upvotes: 5

Related Questions