0

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);
        }
    }
}
3
  • What is the return type of rectOverlap()? Commented Jun 5, 2012 at 20:48
  • Can you post the definition of rectOverlap()? Also, the definition of Vector2D and dimension? I cannot see any problems with the posted part of the code Commented Jun 5, 2012 at 20:54
  • just imagine its result1[i] |= result2[i] |= true; same error. Commented Jun 5, 2012 at 20:55

2 Answers 2

3

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|.

Sign up to request clarification or add additional context in comments.

Comments

3

Never use vector<bool>. Yes, I expect bitwise operators to fail miserably on this type.

See e.g. Alternative to vector<bool>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.