Selecting element from a collection based on bitwise-and result
to_handle actually varies, but the test_consts are all constant, so we can give the compiler a hint here

const uint32_t test_const1 = Constraint3::VAL1 + Constraint3::VAL2;
const uint32_t test_const2 = Constraint1::VAL2 + Constraint1::VAL4 + Constraint1::VAL8;
const uint32_t test_const3 = Constraint2::VAL1 +  Constraint2::VAL2 + Constraint2::VAL4;

uint32_t to_handle = test_const1;
for(ConstraintsContainer_t::iterator it = constraints_.begin(); it != constraints_.end(); ++it) {


EDIT

I've just seen from the linked code that the posted code is completely wrong. So, the remainder of this answer is unlikely to be helpful.

I will however observe that you're timing both the operations you sort-of show above, but also the formatted output. Are you sure you're timing the right thing?



now, we de-reference your iterator a lot in this loop. I don't know how easily the compiler can handle it here, but IMO this is more readable:

    auto &amp;item = it-&gt;get();


(if you don't have C++11 auto, just put the actual type in - I don't know what it is here)

    if( (item &amp; to_handle) == item &amp;&amp;
        (item &amp; test_const2) == item &amp;&amp;
        (item &amp; test_const3) == item ) {
        choosen_.push_back((*it));
        to_handle -= item;
    }
}


Now, the second two conditions in your if never vary, and they simply test that all the set bits of item are inside both masks test_const2=0x0E and test_const3=0x07. That is, none of the set bits are outside test_const2 &amp; test_const3, so

const uint32_t fail_test = ~(test_const2 &amp; test_const3);

//...

    if( (item &amp; to_handle) == item &amp;&amp;
        (item &amp; fail_test) == 0) {
        choosen_.push_back((*it));
        to_handle -= item;
    }


again, the optimizer might have figured that out already, but this version is anyway more expressive.