Dear all,
I was using std::bitset in this manner:
void Foo()
{
enum EBit
{
eBt0 = 0x1,
eBt1 = 0x2,
eBt2 = 0x4,
eBt3 = 0x8
};
std::bitset<4> bts(eBt0 | eBt2);
}
So far so good. But the 'test' function seems to use the position
(which is 2). So a no-op would be:
//FAULT:
//bool bHas = bts.test(eBt2);
To test for the appearance of eBt2 in bts one should do something like
this:
bool bHas1 = (bts & std::bitset<4>(eBt2)).any();
bool bHas2 = (bts & eBt2).any(); //uses implicit conversion
This looks a bit awkward (and one must pay a slight performance
penalty). Do I oversee something? Why should I use the bitset in the
first place and not switch back to a simple unsigned to hold bit
fields?
Wkr,
me
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]