diff --git a/filter_iterator.htm b/filter_iterator.htm new file mode 100644 index 0000000..e662116 --- /dev/null +++ b/filter_iterator.htm @@ -0,0 +1,104 @@ + + +
+ + + ++The filter iterator adaptor ... + + + +
+#include <boost/config.hpp> +#include <algorithm> +#include <iostream> +#include <boost/iterator_adaptors.hpp> + +struct is_positive_number { + bool operator()(int x) { return 0 < x; } +}; + +int main() +{ + int numbers[] = { 0, -1, 4, -3, 5, 8, -2 }; + const int N = sizeof(numbers)/sizeof(int); + + std::copy(boost::make_filter_iterator<is_positive_number>(numbers, numbers + N), + boost::make_filter_iterator<is_positive_number>(numbers + N, numbers + N), + std::ostream_iterator<int>(std::cout, " ")); + std::cout << std::endl; + return 0; +} ++The output is: +
+4 5 8 ++ + +The filter iterator adaptors +models ForwardIterator + + + +
+template <class Predicate, + class Iterator, + class Value = value default, + class Pointer = pointer default, + class Reference = reference default, + class Category = category default, + class Distance = difference type default> +class filter_iterator_generator +{ + typedef ... type; + typedef ... policies_type; +} ++ +
+show another example and explain defaults... + + +
+template <class Predicate, class Iterator> +inline typename detail::filter_generator<Predicate, Iterator>::type +make_filter_iterator(Iterator first, Iterator last, const Predicate& p = Predicate()) ++ + +
Revised 10 Feb 2001
+© Copyright Jeremy Siek 2000. Permission to copy, use, +modify, sell and distribute this document is granted provided this copyright +notice appears in all copies. This document is provided "as is" +without express or implied warranty, and with no claim as to its suitability for +any purpose.
+ + + + diff --git a/filter_iterator_example.cpp b/filter_iterator_example.cpp new file mode 100644 index 0000000..e4bd755 --- /dev/null +++ b/filter_iterator_example.cpp @@ -0,0 +1,30 @@ +// Example of using the filter iterator adaptor from +// boost/iterator_adaptors.hpp. + +// (C) Copyright Jeremy Siek 1999. Permission to copy, use, modify, +// sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. + + +#include