1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<HTML>
<HEAD>
<TITLE>compose4.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>
compose4.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 <list><BR>
#include <algorithm><BR>
#include <functional><BR>
#include <cstdlib><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>
<BR>
int main()<BR>
{<BR>
list<int> coll;<BR>
<BR>
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// insert five random numbers</I></FONT><BR>
generate_n (back_inserter(coll), <I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// beginning of destination range</I></FONT><BR>
5, <I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// count</I></FONT><BR>
rand); <I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// new value generator</I></FONT><BR>
PRINT_ELEMENTS(coll);<BR>
<BR>
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// overwrite with five new random numbers</I></FONT><BR>
<I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// in the range between 0 (including) and 10 (excluding)</I></FONT><BR>
generate (coll.begin(), coll.end(), <I><FONT face="Arial,Helvetica" color="0000FF" size=-1>// destination range</I></FONT><BR>
compose_f_g(bind2nd(modulus<int>(),10),<BR>
ptr_fun(rand)));<BR>
PRINT_ELEMENTS(coll);<BR>
}<BR>
</TT>
</BODY>
</HTML>
|