Reputation: 725
I can't do the following, compiler says no matching operator in std::vector and I don't think I can overload it. So what are my options, apart from only using the 1 vector to store collision results. I'm trying to be extremely cache friendly and I don't want the same bool reset back to false after its been set to true, hence the or.
void CollisionDetection(const vector<Vector2D>& position1,
const vector<Vector2D>& position2,
dimension dim1, dimension dim2,
vector<bool>& result1, vector<bool>& result2)
{
assert(position1.size()==result1.size());
assert(position2.size()==result2.size());
for(int i=0;i<position1.size();i++)
{
for(int j=0;j<position2.size();j++)
{
result1[i] |= result2[i] |=
rectOverlap(position1[1], position2[i], dim1, dim2);
}
}
}
Upvotes: 0
Views: 1611
Reputation: 60778
Never use vector<bool>
. Yes, I expect bitwise operators to fail miserably on this type.
See e.g. Alternative to vector<bool>
Upvotes: 3
Reputation: 21900
std::vector<bool>
is a specialization of a std::vector
. This specialization saves space by using 1 bit for each bool
, instead of 1 byte.
std::vector<bool>::operator[]
returns a reference wrapper(in order to allow this space-save optimization), which apparently does not implement operator|
.
Upvotes: 3