Kinds of containers

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 21 12:07:48 PDT 2015


On Wednesday, 21 October 2015 at 18:48:18 UTC, Brad Anderson 
wrote:
> All that said, I agree with you that the implicit copying isn't 
> really all that desirable. Perhaps there is a better way. What 
> if instead of value semantics we had unique containers (akin to 
> std.typecons.Unique or unique_ptr in C++) and required people 
> to always state whether it was a copy or move? That takes care 
> of the error prone implicit copying while retaining the 
> performance characteristics.

Well, we could always have a wrapper for reference type 
containers that turns them into a value type, though I'm not sure 
that that really does much in terms of the efficiency you were 
talking about. But it could means that you'd end up passing 
around a pointer to that rather than the container itself, in 
which case, maybe that solves the problem for those who don't 
want a container to be managed by the GC and don't want it to be 
ref-counted when passing it around? I don't know.

Even if we're talking about a reference type container that's 
just straight up ref-counted or managed by the GC, there are 
still ways to pass around pointers or pseudo pointers to it which 
don't involve ref-counting if that's the real concern. Though 
honestly, I'd be concerned if a container was being passed around 
so much that ref-counting was a concern. A range would be better 
in most cases - but you really wouldn't want to be passing around 
the container as a value type in either case, because that would 
just copy it. So, if ref-counting is the concern, I wouldn't 
think that it would be all that hard for someone who cares to 
pass around something else which referred to the container and 
wasn't ref-counted.

- Jonathan M Davis


More information about the Digitalmars-d mailing list