Topic: Needed: vector<bool> specialization for VC++, 6.0


Author: "Kurt" <kkurt@ifsx.net>
Date: 1999/10/30
Raw View
I am looking for source code for a specialization of vector for bool. I am
using VC++, 6.0. The specializaion, vector<_Bool, _Bool_allocator>, in the
<vector> header that comes with VC++ has a bug.  The insert(iterator, bool)
method sometimes zeroes valid bools.

Kurt
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: hsutter@peerdirect.com (Herb Sutter)
Date: 1999/10/30
Raw View
On 30 Oct 99 01:34:18 GMT, "Kurt" <kkurt@ifsx.net> wrote:
>I am looking for source code for a specialization of vector for bool. I am
>using VC++, 6.0. The specializaion, vector<_Bool, _Bool_allocator>, in the
><vector> header that comes with VC++ has a bug.  The insert(iterator, bool)
>method sometimes zeroes valid bools.

You will find problems with even bug-free standard-conforming
implementations of vector<bool>. Unfortunately, the best advice I can
give practitioners is to avoid it by default, as follows:

1. If:

   a) you know that your library implementation actually uses a packed-
      representation optimization for vector<bool>; AND

   for a particular container-of-bools object in your application:

   b) you know (from performance measurements) that it benefits from the
      packed representation; AND

   c) you know it will never be used with any of the standard
      algorithms;

then go ahead and use vector<bool> for that particular container object.

2. In all other cases (i.e., by default), avoid vector<bool>. In code
where performance isn't critical just use a deque<bool>, otherwise use a
vector<char> and cast to and from bool as needed when accessing the
container. (Yes, I agree the latter is odious and a kludge, and I
dislike that I have to recommend it as one of the best two alternative
solutions for avoiding vector<bool>, but there it is.)

See the May 1999 and July/August 1999 issues of C++ Report for more
information about vector<bool> and deque.

Herb

---
Herb Sutter (mailto:hsutter@peerdirect.com)

PeerDirect Inc.     2695 North Sheridan Way, Suite 150
www.peerdirect.com  Mississauga Ontario Canada L5K 2N6
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]