Boost logo

Boost Users :

Subject: Re: [Boost-users] doubt on lambda expression
From: Emanuele Rocci (rocciemanuele_at_[hidden])
Date: 2009-11-11 11:01:33


Hi Roman Thanks! It works and thanks for Phoenix advice!Mn

Date: Wed, 11 Nov 2009 13:20:26 +0100
From: roman.perepelitsa_at_[hidden]
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] doubt on lambda expression

2009/11/11 Emanuele Rocci <rocciemanuele_at_[hidden]>

Hi AllI started playing with boost::lambda and I need some help or some clarification about itor some hint to better understanding how does it work.

I have this piece of code
using namespace boost::lambda;using boost::lambda::var;

int main(int argc, char** argv) { std::vector< int > myList;
   myList.push_back(100); myList.push_back(200); int interval = 20;

   std::for_each( myList.begin(), myList.end(), (
        std::cout << "value: " << _1 << "\n", std::cout << "interval: " << var( interval ) << "\n",
        var( interval )++ ));}

Instead of std::cout << "value: " << _1 << "\n",do this
  std::cout << constant("value: ") << _1 << "\n",
It's described here: http://www.boost.org/doc/libs/1_40_0/doc/html/lambda/using_library.html#lambda.introductory_examples.

By the way, if you are just starting with lambda, it's better to use Boost.Phoenix instead.
Roman Perepelitsa.
_________________________________________________________________
Carica e scarica in un clic. Fino a 25 GB su SkyDrive
http://www.windowslive.it/skyDrive.aspx
--_ef5d65dc-e4e9-420a-9033-1d3530b1541d_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Hi Roman Thanks!&nbsp;<div>It works and thanks for Phoenix advice!<div>Mn<br><div><br></div><div><br><br><hr id="stopSpelling">Date: Wed, 11 Nov 2009 13:20:26 +0100<br>From: roman.perepelitsa_at_[hidden]<br>To: boost-users_at_[hidden]<br>Subject: Re: [Boost-users] doubt on lambda expression<br><br><div class="ecxgmail_quote">2009/11/11 Emanuele Rocci <span dir="ltr">&lt;<a href="mailto:rocciemanuele_at_[hidden]">rocciemanuele_at_[hidden]</a>&gt;</span><br><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex">

<div>
Hi All<div>I started playing with <font face="'Courier New'">boost::lambda</font> and I need some help or some clarification about it</div><div>or some hint to better understanding how does it work.</div><div><br>
</div><div>I have this piece of code</div><div><br></div><div><div><font face="'Courier New'">using namespace boost::lambda;</font></div><div><font face="'Courier New'">using boost::lambda::var;</font></div>
</div><div><font face="'Courier New'"><br></font></div><div><font face="'Courier New'">int main(int argc, char** argv) {</font></div><div><div><font face="'Courier New'">&nbsp;&nbsp; std::vector&lt; int &gt; myList;</font></div>
<div><font face="'Courier New'">&nbsp;&nbsp; myList.push_back(100);</font></div><div><font face="'Courier New'">&nbsp;&nbsp; myList.push_back(200); &nbsp; &nbsp;</font></div><div><font face="'Courier New'">&nbsp;&nbsp; int interval = 20;</font></div>
<div><font face="'Courier New'"><br></font></div><div><div><font face="'Courier New'">&nbsp;&nbsp; std::for_each( myList.begin(), myList.end(),</font></div><div><font face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;(</font></div>
<div><font face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::cout &lt;&lt; "value: " &lt;&lt; _1 &lt;&lt; "\n",</font></div><div><font face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;std::cout &lt;&lt; "interval: " &lt;&lt; var( interval ) &lt;&lt; "\n",</font></div>
<div><font face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;var( interval )++</font></div><div><font face="'Courier New'">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;));</font></div><div><font face="'Courier New'">}</font></div></div></div></div></blockquote>
<div><br></div><div>Instead of</div><div><font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp;std::cout &lt;&lt; "value: " &lt;&lt; _1 &lt;&lt; "\n",</font></div><div>do this</div><div>
<font class="ecxApple-style-span" face="'courier new', monospace">&nbsp;&nbsp;std::cout &lt;&lt; constant("value: ") &lt;&lt; _1 &lt;&lt; "\n",</font></div><div><br></div><div>It's described here: http://www.boost.org/doc/libs/1_40_0/doc/html/lambda/using_library.html#lambda.introductory_examples.</div>
<div><br></div><div>By the way, if you are just starting with lambda, it's better to use Boost.Phoenix instead.</div><div><br></div><div>Roman Perepelitsa.</div></div></div></div></div> <br /><hr />Personalizza il tuo spazio online: <a href='http://www.windowslive.it/spaces.aspx' target='_new'>ritagliati il tuo Spaces</a></body>
</html>
--_ef5d65dc-e4e9-420a-9033-1d3530b1541d_--


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net