If T[new] is the container for T[], then what is the container for T[U]?
Max Samukha
samukha at voliacable.com.removethis
Sun Apr 26 01:40:20 PDT 2009
On Sat, 25 Apr 2009 08:07:52 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
>It looks we can't make it with only T[]. We need a genuine container
>type, and T[new] was suggested. It would probably have value semantics.
>
>T[U] seems to have the same problem. If T[U] is the range, then how do
>you call the container?
>
>If we follow through with a no-garbage-collected option for the core
>types, then we also need to distinguish between a slice and its
>container. The fact that we (almost) got away with T[] being at the same
>time the container and the slice was that the garbage collector would
>collect all unused slices.
>
>
>Andrei
T![] T![U] (kidding)
T[:] T[:U]
FWIW, Qt uses by-value containers with COW and it looks like they are
ok for many usages. I'd like to see a std.containers module defining
containers with semantics based on a policy:
enum CopyPolicy
{
Always, // by value
OnWrite, // by value with COW
Never // by reference
}
Then we could use the most appropriate policy for built-in arrays (I
think it should be by-value with COW).
module object;
import std.containers;
template Array(T)
{
alias CoolArray!(T, CopyPolicy.OnWrite) Array;
}
and still be able to use containers with different policies when
necessary.
More information about the Digitalmars-d
mailing list