Reputation: 1002
What I had before was a string of 1s and 0s and I could simply check whether some range equals to a sequence I wanted:
if (myString.substr(0, 4) == "1110") ...
For memory reasons, I've made this string into vector<bool>
, since one bool in vector only takes 1 bit instead of 1 byte.
Now, here's a problem. I want to do same comparison as I did with substr
. Possibly without anything like:
if(myVector[0] == true && myVector[1] == true && ...)
or
vector<bool> tmpVector;
tmpVector.push_back(true);
tmpVector.push_back(true);
...
if (myVector == tmpVector) ...
Is there a more elegant solution to this?
Upvotes: 4
Views: 96
Reputation: 23058
bool tmpVector[4] = {true, true, true, false};
if (std::equal(myVector.begin(), myVector.begin() + 4, tmpVector)) {
}
Upvotes: 5