cam
cam

Reputation: 9033

Are Bitsets actually Bools?

In C++, are bitsets actually a set of bools? Doesn't this defeat the purpose of using a BitSet because bools are 32 bits (I think...)?

Upvotes: 1

Views: 314

Answers (2)

GManNickG
GManNickG

Reputation: 503795

They represent a collection of bool's, but those values are really stored as bits in an unsigned long.

The size of a bool is not necessary any number of bits, neither is an unsigned long. (Though the minimum number of bits for any data type is 8, and for an unsigned long it must be at least 32.)

Upvotes: 8

Tyler McHenry
Tyler McHenry

Reputation: 76650

No, std::bitsets are not actually bools, they are actually bitsets. Who told you that they were bools?

Are you perhaps getting confused with the controversy over std::vector<bool>? Which is, incidientally, the opposite issue, since it looks like a set of bools but is actually a bitset.

Upvotes: 6

Related Questions