Jump to content
  • Advertisement
Sign in to follow this  

c++ container comparison

This topic is 2345 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

According to http://www.cplusplus.com/reference/stl/vector/operators/, C++ vector comparison uses algorithm equal, which doesn't appear to do any range checking. No mention is made of how vectors of different sizes are handled, leading me to expect that it crashes or gives incorrect results. But when I test it, it appears to work.

I assume that comparisons of different size containers actually are handled, but why isn't this mentioned?

Share this post


Link to post
Share on other sites
Advertisement

According to http://www.cplusplus.com/reference/stl/vector/operators/, C++ vector comparison uses algorithm equal, which doesn't appear to do any range checking. No mention is made of how vectors of different sizes are handled, leading me to expect that it crashes or gives incorrect results. But when I test it, it appears to work.

I assume that comparisons of different size containers actually are handled, but why isn't this mentioned?

I imagine it isn't mentioned because whoever wrote that description, which is in no way official or associated with the ISO C++ standard, left it out.

Table 96 in section 23.1 in the C++ standard specifies (regarding all standard containers)
== is an equivalence relation.
[font="Courier New"]distance(a.begin(), a.end()) == distance(b.begin(), b.end()) &&
equal(a.begin(), a.end(), b.begin())[/font][/quote]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!