Tech Off Post

Single Post Permalink

View Thread: a selector iterator
  • User profile image

    Stephan T. Lavavej described how to eliminate loops in code using standard algorithms in his excellent installment algorithms and functors.  In particular, he showed how to use an algorithm to count all even numbers in a sequence.

    Is it possible to harness STL to create a list of all even numbers in a sequence, without loops or custom iterators?  I currently use custom iterators for the purpose, but I feel a forward iterator factorization of std::count would be very useful, along the lines of the following code?

    std::count (select (begin, even), end, True) == std::count (begin, end, even)