Is the use of std::vector objects in C++ acceptable, or should I use an alternative?

后端 未结 7 994
有刺的猬
有刺的猬 2020-11-29 09:29

I\'m working with a user-defined quantity of bits (I\'m holding a three-dimensional array of bits, so the size increases cubically - assume no less then 512 bits), and need

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 09:42

    The critique is that vector is the only standard container that doesn't fully conform to the standard's container requirements. That's a bit of a surprise.

    Another point is that vector forces a space optimization on everyone (by storing bits), when perhaps some users would have preferred a speed optimization.

    Other than that, the major deviation is that the container cannot return a reference to its members, because it doesn't store any bools. That will make the odd standard library algorithm fail to compile for vector.

    If you can live with that, and it fits your needs for everything else, it is quite ok to use it.

提交回复
热议问题