Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

c++ container comparison

This topic is 2525 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
Because that's not the world's best reference source? The C++ standard does specify that sizes are checked.

Share this post


Link to post
Share on other sites

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!