Set iterator difference

Hi all!
I'd like to know if C++ STL has a way to count elements in a certain range from a set. I tried using lower_bound/upper_bound, but I couldn't subtract a set<int>::iterator from another.

Is there any other way to do that using STL?

Thank you very much,
Try set::size or set::count
http://www.cplusplus.com/reference/stl/set/
Like distance?
http://www.cplusplus.com/reference/std/iterator/distance.html

Just be sure to read the information and make sure it works with the container you are using...
Another way is via std::count_if and boost::lambda (the boost::lambda just allows me to do this with one line of code instead of writing a function object):

1
2
cout << std::count_if( s.begin(), s.end(),
  boost::lambda::_1 >= MIN && boost::lambda::_1 <= MAX );


Man, I've got to learn boost::lambda...I read through some of the information at boost.org, but I still haven't actually used it in my own code for anything... Is that the same one that has the bind stuff?
boost::lambda has its own version of bind, but there is also the boost::bind library.

It's cool, but has a steep learning curve.

Topic archived. No new replies allowed.