Home > Articles > Programming > C/C++

Extended STL: Filtered Iteration

  • Print
  • + Share This
In this chapter, Matthew Wilson explains that a filtering iterator adaptor must be instantiated from an iterator pair defining the viable range of the adapted range, and that by applying the adapted_iterator_traits traits class, we can achieve a simple definition for what is a sophisticated iterator adaptation.
This chapter is from the book
  • 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

42.1 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"));
  • + Share This
  • 🔖 Save To Your Account