Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > bitset
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 9362 of 10087
Post > Topic >>

bitset

by "gast128@[EMAIL PROTECTED] " <gast128@[EMAIL PROTECTED] > Mar 11, 2008 at 01:44 AM

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! ]
 




 4 Posts in Topic:
bitset
"gast128@[EMAIL PROT  2008-03-11 01:44:47 
Re: bitset
Michael.Boehnisch@[EMAIL   2008-03-11 12:12:28 
Re: bitset
Thomas Lehmann <t.lehm  2008-03-11 12:42:33 
Re: bitset
"gast128@[EMAIL PROT  2008-03-11 21:54:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 17:08:31 CDT 2008.