Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ STL vector<bool> et. al.



Jerry Feldman wrote:
> In the code I'm hacking they have a home grown boolean array. One example 
> is that it has a boolean array of business days, holidays and a few 
> others. Rather than use the existing class I am somewhat leaning toward 
> replacing the boolean array class with either std::vector<bool> or std::bitset. 
> Note that the original code I am porting contained its own string, array, 
> map and set classes, which I am replacing with either the STL or RogueWave 
> analogs to the STL. (What I'm doing is writing part of a new product, but 
> I need to preserve many of the classes.)

Don't use vector<bool>, at least not before you understand some of the issues
with it.  This article explains some of the quirkiness:
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=98&rl=1

>From the article:
> Although the committee didn't actively deprecate vector<bool>, C++
> newsgroups and discussion forums have thenceforth advised programmers to
> stay away from it. In the Lillehammer meeting in April 2005, vector<bool>
> was discussed again. This time, there was general agreement about
> deprecating vector<bool> and introducing its functionality under a
> different name, e.g. bit_vector. With the adoption of this approach, it
> might be possible to remove the vector<bool> specialization from the next
> C++ standard.

Replacing the other types (string, array, map, set) probably isn't as fraught
with peril, and is unquestionably the right thing to do, unless the original
had different memory management semantics than the STL (ie if the old code
stored pointers to the object instead of copies of the object).

Matt

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org