Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-11-26 11:44:27


Hi Matt,

On 11/26/01 12:27 AM, "Matt Austern" <austern_at_[hidden]> wrote:
> Actually, I have a slightly different question. (I think I brought this
> up when we talked about this in Redmond.)
>
> My question: why do we need both bitset<> and vector<bool>? What are
> the real differences?
>
> Except for trivial syntactic issues, here's all I can really come up
> with:
> - vector<bool> provides STL iterators and dynamic resizing, and
> bitset doesn't.
> - bitset provides conversion to/from long, simple I/O, and
> bitwise operations. vector<bool> doesn't provide any of
> those things.

Also there's the issue of whether increasing significance of the bits goes
left to right or right to left. For bitset it goes right to left. I'm not
sure it is meaningful to talk about significant bits of vector<bool>, but I
would guess it is left to right.

>
> Seems to me that we should really be looking at extending vector<bool>,
> not extending bitset. A few trivial addons to vector<bool>, and we've
> got a class that does everything bitset does and more. (Yeah, I know:
> vector<bool> shouldn't be spelled vector<bool>, it should be spelled
> bit_vector. Details.)

I would argue against this. One mark of a good component or function is that
is has a clear and focused purpose. I think by mixing the functionality of
vector<bool> with that of bitset you end up with something that is more
complex and harder to understand. Also, I think it is a bad idea to use
iterators to traverse a bitset, they are horribly slow.

Cheers,
Jeremy

-- 
Jeremy Siek                          http://www.osl.iu.edu/~jsiek
Ph.D. Student, Indiana Univ. B'ton   email: jsiek_at_[hidden]
C++ Booster (http://www.boost.org)   office phone: (812) 855-3608

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk