mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
added another example
[SVN r9103]
This commit is contained in:
parent
a5c3dcdd02
commit
a84c46f6e3
@ -189,8 +189,32 @@ This function provides a convenient way to create filter iterators.
|
|||||||
|
|
||||||
<h3>Example</h3>
|
<h3>Example</h3>
|
||||||
|
|
||||||
In this example we print the positive number again, this time using
|
In this example we print out all numbers in the array that are
|
||||||
the <tt>make_filter_iterator()</tt> function.
|
greater than negative two.
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int numbers[] = { 0, -1, 4, -3, 5, 8, -2 };
|
||||||
|
const int N = sizeof(numbers)/sizeof(int);
|
||||||
|
|
||||||
|
std::copy(boost::make_filter_iterator(numbers, numbers + N,
|
||||||
|
std::bind2nd(std::greater<int>(), -2)),
|
||||||
|
boost::make_filter_iterator(numbers + N, numbers + N,
|
||||||
|
std::bind2nd(std::greater<int>(), -2)),
|
||||||
|
std::ostream_iterator<int>(std::cout, " "));
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
The output is:
|
||||||
|
<pre>
|
||||||
|
0 -1 4 5 8
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
In the next example we print the positive numbers using the
|
||||||
|
<tt>make_filter_iterator()</tt> function.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
struct is_positive_number {
|
struct is_positive_number {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user