Well, they tell me that it would be better. I need | = elements of one vector with another. That is, I want
void orTogether(vector<char>& v1, const vector<char>& v2)
{
typedef vector<char>::iterator iter;
for (iter i = v1.begin(), iter j = v2.begin() ; i != v1.end(); ++i, ++j)
*i |= *j;
}
I cannot use for_each due to the need to process 2 collections. I guess I could do something like
struct BitWiseOr
{
char operator()(const char& a, const char& b) {return a | b;}
};
void orTogether2(vector<char>& v1, const vector<char>& v2)
{
transform(v1.begin(), v1.end(), v2.begin(),
v1.begin(), BitwiseOr());
}
Is this a more efficient solution, even if the top is in place, but the bottom is the destination? This is right in the middle of the processing loop, and I need the fastest code.
Edit: Added (obvious?) Code for BitwiseOr. In addition, I get a lot of comments about unrelated things like checking v2 lengths and changing names. This is just an example, the real code is more complex.
, . orTogether2 , orTogether, . , Together2 4 MSVC9. , , , - , . .