Jump to content
  • Advertisement
Sign in to follow this  
pikapika

cout number of elementsbetween two iterators

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

cout number of elements between two iterators i have cit = unique(mcit->begin(),mcit->end(),cmpeqrank); and now i want to count between mcit->begin() and cit to see how many unique elements there are. i tried the stl template functions count_if and count but they count only elements which are equal to a result when i just want to count all elements.

Share this post


Link to post
Share on other sites
Advertisement
Hi
you can use count_if with an unary predicate the always returns true, this should could all elements in the range [beg,end)

Edit: You should use Mc Cloud's method, and if you are using random access iterators you can simply subtract them just as you can it with pointers.

Share this post


Link to post
Share on other sites
thankyou very much!! may ask where you found this function i could not find it on

http://cppreference.com/all_cpp_functions.html

Share this post


Link to post
Share on other sites
There s an excellent book about the STL:
The C++ Standard Library: A Tutorial and Reference
by Nicolai M.Josuttis
ISBN:0-201-37926-0
$59.99

Its worth the money

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!