Kinds of containers
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Wed Oct 21 11:38:08 PDT 2015
On Wednesday, 21 October 2015 at 18:14:39 UTC, jmh530 wrote:
> On Wednesday, 21 October 2015 at 18:05:07 UTC, Jonathan M Davis
> wrote:
>>
>> However, I completely fail to understand why you'd ever want a
>> container that was a value type. In my experience, it's very
>> error-prone and adds no value.
>
> Are you saying there isn't a reason to use static arrays?
A static array is of a fixed size, which almost no other
containers are. It also lives entirely on the stack, which almost
no other containers do. If there's a container that lives
entirely on the stack, then maybe it would make sense for it to
be a value type, but _very_ few containers fall in that category,
and all of the classic containers like vector, linked list, map,
etc. have no business being value types IMHO. It's just
error-prone. Heck, static arrays are quite error-prone thanks to
the fact that they convert to dynamic arrays, but they do serve a
purpose. So, maybe there are containers that fall in the same
category, but I expect that such containers are pretty obviously
value types and not reference types, because their nature makes
them that way. Regardless, I don't see how it's reasonable in
general to make a container be a value type. It's just asking for
trouble. If there's any question at all whether a container
should be a value type or a reference type, IMHO, it should be a
reference type.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list