Sign in to follow this  

Multiple vector checks

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What's up GameDevers, If I have two separate vectors and I wanted to and check the elements of one vector against the elements of the other vector iterating through both in an if, how would this best be accomplished?

Share this post


Link to post
Share on other sites
I usually do this to check if a value in one vector is different from the other


for (std::vector<int>::iterator it1 = vector1.begin(); it1 != vector1.end(); ++it1)
{
for (std::vector<int>::iterator it2 = vector2.begin(); it2 != vector2.end(); ++it2)
{
if ((*it1) != (*it2))
{
break; // 2 different values
}
}
}


if there is a better and faster code for this please let me know
would very much appreciate it

otherwise if you just want to see if the 2 vectors are equal indeed use == and it will return a bool

Share this post


Link to post
Share on other sites
To be clear, I am not checking the equality of the elements of the vectors, I am checking collisions between elements of the vectors; projectiles to objects namely. The vectors store pointers to the game objects.

@ projectghost,

My algorithm shares similarity with yours and I will most likely stick to it.

Share this post


Link to post
Share on other sites

This topic is 2849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this