STL like Vector,Pair, Map
Tim Keating
mrtact+dnewsgroup at gmail.com
Wed Nov 14 00:10:26 PST 2007
Bill Baxter Wrote:
> > Why?
>
> STL containers act like value types.
>
> std::vector<int> a,b;
> ...// put some stuff in vector a
> b = a; // now b has a copy of every element of a
> a[4] = 9; //b[4] unchanged
>
>
> In D currently to get that behavior have to do .dup:
> int[] a,b;
> b = a.dup;
But . . . the reason the STL uses value types is to minimize the complexity inherent in determining who owns objects passed by reference. Doesn't that problem just _go away_ in a garbage-collected language?
Could you not build an interface-compatible set of STL containers that use reference semantics instead? Admittedly, that's a big caveat for porting, but I wonder how much code you would actually have to change . . .
TK
More information about the Digitalmars-d
mailing list