mirror of
https://github.com/boostorg/compose.git
synced 2026-01-19 04:02:16 +00:00
60 lines
2.9 KiB
HTML
60 lines
2.9 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>compose2.cpp</TITLE>
|
|
</HEAD>
|
|
|
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
|
|
|
<TABLE HEIGHT=40 WIDTH="100%">
|
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
|
<FONT face="Arial,Helvetica" size=+2><B>
|
|
compose2.cpp
|
|
</B></FONT>
|
|
</TD></TR></TABLE><BR>
|
|
|
|
<FONT face="Arial,Helvetica"><B>
|
|
The following code example is taken from the book<BR>
|
|
<A HREF="http://www.josuttis.com/libbook/" TARGET="_top">
|
|
The C++ Standard Library - A Tutorial and Reference</A><BR>
|
|
by Nicolai M. Josuttis, Addison-Wesley, 1999<BR>
|
|
<A HREF="http://www.josuttis.com/libbook/copyright.html">
|
|
© Copyright</A> Nicolai M. Josuttis 1999<BR>
|
|
</B></FONT>
|
|
|
|
<BR><BR><TT>
|
|
#include <iostream><BR>
|
|
#include <vector><BR>
|
|
#include <algorithm><BR>
|
|
#include <functional><BR>
|
|
#include "<A href="print.hpp.html">print.hpp</A>"<BR>
|
|
#include "<A href="compose.hpp.html">compose.hpp</A>"<BR>
|
|
using namespace std;<BR>
|
|
using namespace boost;<BR>
|
|
<BR>
|
|
int main()<BR>
|
|
{<BR>
|
|
vector<int> coll;<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// insert elements from 1 to 9</I></FONT><BR>
|
|
for (int i=1; i<=9; ++i) {<BR>
|
|
coll.push_back(i);<BR>
|
|
}<BR>
|
|
PRINT_ELEMENTS(coll);<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// remove all elements that are greater than four and less than seven</I></FONT><BR>
|
|
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// - retain new end</I></FONT><BR>
|
|
vector<int>::iterator pos;<BR>
|
|
pos = remove_if (coll.begin(),coll.end(),<BR>
|
|
compose_f_gx_hx(logical_and<bool>(),<BR>
|
|
bind2nd(greater<int>(),4),<BR>
|
|
bind2nd(less<int>(),7)));<BR>
|
|
<BR>
|
|
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// remove ``removed'' elements in coll</I></FONT><BR>
|
|
coll.erase(pos,coll.end());<BR>
|
|
<BR>
|
|
PRINT_ELEMENTS(coll);<BR>
|
|
}<BR>
|
|
</TT>
|
|
</BODY>
|
|
</HTML>
|