O'Reilly logo

Extended STL, Volume 1: Collections and Iterators by Matthew Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 42. Filtered Iteration

 

If you think you’ve arrived, you’re ready to be shown the door.

 
 --Steve Forbes
 

I can give you my word, but I know what it’s worth and you don’t.

 
 --Nero Wolfe

Introduction

We saw in Chapter 36 that transforming an iterator is a matter of applying a unary function to the dereference. Can we do this with a predicate, to filter out items? We might imagine something like the following:

using recls::stl::search_sequence;
search_sequence  files(".", "*", recls::FILES | recls::RECURSIVE);

std::copy(filter(files.begin(), is_readonly())
    , filter(files.end(), is_readonly())
    , std::ostream_iterator<search_sequence::value_type>(std::cout
                                                       , "\n"));

An Invalid Version

How would this work? Naturally, filter() will be a creator function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required