diff --git a/filter_iterator.htm b/filter_iterator.htm index e662116..3c79776 100644 --- a/filter_iterator.htm +++ b/filter_iterator.htm @@ -19,25 +19,179 @@ Defined in header
-The filter iterator adaptor ... +The filter iterator adaptor creates a view of an iterator range in +which some elements of the range are skipped over. A Predicate +function object controls which elements are skipped. When the +predicate is applied to an element, if it returns true then +the element is retained and if it returns false then the +element is skipped over. +
+namespace boost { + template <class Predicate, class Iterator, ...> + class filter_iterator_generator; + + template <class Predicate, class Iterator> + typename filter_iterator_generator<Predicate, Iterator>::type + make_filter_iterator(Iterator first, Iterator last, const Predicate& p = Predicate()); +} ++ + +
+template <class Predicate, + class Iterator, + class Value = std::iterator_traits<Iterator>::value_type, + class Pointer = std::iterator_traits<Iterator>::pointer, + class Reference = std::iterator_traits<Iterator>::reference, + class Category = std::iterator_traits<Iterator>::iterator_category, + class Distance = std::iterator_traits<Iterator>::difference_type, +class filter_iterator_generator +{ +public: + typedef ... type; // the filter iterator_adaptor type + typedef ... policies_type; // the filter policies type +} +
-#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); + typedef boost::filter_iterator_generator<is_positive_number, int*, int> Gen; + is_positive_number predicate; + Gen::policies_type policies(numbers + N, predicate); + Gen::type filter_iter_first(numbers, policies); + Gen::type filter_iter_last(numbers + N, policies); + + std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator<int>(std::cout, " ")); + std::cout << std::endl; + return 0; +} ++The output is: +
+4 5 8 ++ + +
Parameter | Description | +
---|---|
Predicate | +The function object that determines which elements are retained and which elements are skipped. + |
Iterator | +The iterator type being wrapped. This type must be a model + of either the InputIterator concept or the OutputIterator concept. | +
Value | +The value_type for the iterator adaptor. Typically the default for
+this parameter is the appropriate type[1]. +Default: std::iterator_traits<Iterator>::value_type |
+
Pointer | +The pointer type for the iterator adaptor. Typically the default for
+this parameter is the appropriate type. +Default: std::iterator_traits<Iterator>::pointer |
+
Reference | +The reference type for the iterator adaptor. Typically the default for
+this parameter is the appropriate type. +Default: std::iterator_traits<Iterator>::reference |
+
Category | + +The iterator_category type for the iterator adaptor.
+Typically the
+default for this parameter is the appropriate type. If you override
+this parameter, do not use bidirectional_iterator_tag
+because filter iterators can not go in reverse. +Default: std::iterator_traits<Iterator>::iterator_category |
+
Distance | +The difference_type for the iterator adaptor. Typically the default for
+this parameter is the appropriate type. +Default: std::iterator_traits<Iterator>::difference_type |
+
+ +
+ +
+template <class Predicate, class Iterator> +typename detail::filter_generator<Predicate, Iterator>::type +make_filter_iterator(Iterator first, Iterator last, const Predicate& p = Predicate()) ++ +This function provides a convenient way to create filter iterators. + +
+struct is_positive_number { + bool operator()(int x) { return 0 < x; } +}; int main() { int numbers[] = { 0, -1, 4, -3, 5, 8, -2 }; @@ -56,39 +210,12 @@ The output is:-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()) -+[1] If the compiler does not support partial +specialization and the wrapped iterator type is a builtin pointer then +the Value type must be explicitly specified (don't use the +default).