== Quote from Andrei Alexandrescu (seewebsiteforem...@erdani.org)'s article > Walter and I have been discussing what the regime of statically-sized > arrays should be. In short, the behavior that's most consistent with > everything else is to treat them as values. > This also brings the problems of e.g. containers - should they have > consistent value semantics (like in STL)
Oh God no! I always thought the value semantics of STL containers were largely a kludge to work around the fact that C++ doesn't have garbage collection. They make it easier to use RAII for memory management, since every object has a clear owner. This leads to tons and tons of copying if code is written the obvious way, and lots of kludges to prevent it. > or consistent reference > semantics (like in Java)? Yes. Largely to be consistent with builtin dynamic arrays and AAs, and for efficiency, to avoid hidden copying. I consider the builtin static arrays to be just a niche performance hack anyhow, and hardly ever use them because they're too inflexible, so consistency with them isn't as important. If you want to duplicate something before passing it to something else, attaching a simple .dup to the end as in foo(myArray.dup) works pretty darn well. All the standard containers should simply have a .dup method, which works similarly to the builtin dynamic array .dup method.