|
|
Fredrik Eriksson <fe79}--at--{yahoo}--dot--{com> wrote:
> On Tue, 25 Mar 2008 17:34:14 +0100, Nicolas Alvarez
> <nic### [at] gmailisthebestcom> wrote:
> > C++ STL vector template class has a specialization for 'bool' that uses
> > 1 bit per element too. That is, a vector<bool> takes 1 bit per element.
> Yes, but that specialisation is largely considered a mistake
The alternative would be that there's no specialization, in which
case each element could take even 4 bytes (from which only 1 bit is
actually used).
I don't see any problem in having an efficient boolean vector.
If it doesn't work with some STL algorithms, then it doesn't. In
the vast majority of cases there isn't any logical use for STL
algorithms for a bool vector anyways (why would you, for example,
try to sort a bool vector? It doesn't make any sense).
Of course std::bitset should be used whenever possible. However,
it's not always possible. In that case std::vector<bool> is the
next best thing.
--
- Warp
Post a reply to this message
|
|