 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Fei Liu Guest
|
Posted: Thu May 11, 2006 1:21 pm Post subject: how to read boost::lambda expression |
|
|
I tried the boost::lambda library in the following test code and I
found it difficult to parse/interpret what the code does in a sense how
a compiler parse/interpret it. For example, when both a compiler and I
see 'a=b+c' as assign the result of addition to a 3rd number in a
straightfoward maner but the lambda expressions are in a different
league. How does a compiler parse/interpret the lambda statements in
the following code? The comments are mine. Thanks for your help.
#include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/function.hpp>
int main(){
using namespace boost::lambda;
// this executes an unamed function with 3 arguments?
(std::cout << _1 << " " << _3 << " " << _2 << "!\n")
("hello", "friend", "my");
// this defines a function but there is no function body { ... } ?
boost::function<void(int, int, int)> f=
std::cout << _1 << "*" << _2 << "+" << _3
<< "=" << _1*_2+_3 << "\n";
f(1,2,3);
f(3,2,1);
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Carl Barron Guest
|
Posted: Fri May 12, 2006 12:21 am Post subject: Re: how to read boost::lambda expression |
|
|
In article <1147290951.170654.251440 (AT) i39g2000cwa (DOT) googlegroups.com>, Fei
Liu <fei.liu (AT) gmail (DOT) com> wrote:
| Quote: | I tried the boost::lambda library in the following test code and I
found it difficult to parse/interpret what the code does in a sense how
a compiler parse/interpret it. For example, when both a compiler and I
see 'a=b+c' as assign the result of addition to a 3rd number in a
straightfoward maner but the lambda expressions are in a different
league. How does a compiler parse/interpret the lambda statements in
the following code? The comments are mine. Thanks for your help.
|
lambd uses a techinque of template metaprogramming called expression
templates to have the complier 'compute' a functor to execute the given
expression. Perhaps the pdf at
mrl.nyu.edu/~mkg/professional/programming/expr_templates.pdf
might explain the technique as it is a bit complicated for a newsgroup
message...
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Niek Sanders Guest
|
Posted: Fri May 12, 2006 12:21 am Post subject: Re: how to read boost::lambda expression |
|
|
Fei Liu wrote:
| Quote: | I tried the boost::lambda library in the following test code and I
found it difficult to parse/interpret what the code does in a sense how
a compiler parse/interpret it. For example, when both a compiler and I
see 'a=b+c' as assign the result of addition to a 3rd number in a
straightfoward maner but the lambda expressions are in a different
league. How does a compiler parse/interpret the lambda statements in
the following code? The comments are mine. Thanks for your help.
|
Check out the paper on "Expression Templates" written by Todd
Veldhuizen:
http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html
The book "C++ Templates: The Complete Guide" by Vandevoorde and
Josuttis also has a chapter (#1 on the topic. I haven't read this
book yet, so I can't say anything about the quality of their
exposition.
- Niek Sanders
http://www.cis.rit.edu/~njs8030/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Fei Liu Guest
|
Posted: Fri May 19, 2006 10:21 am Post subject: Re: how to read boost::lambda expression |
|
|
Carl Barron wrote:
| Quote: | In article <1147290951.170654.251440 (AT) i39g2000cwa (DOT) googlegroups.com>, Fei
Liu <fei.liu (AT) gmail (DOT) com> wrote:
I tried the boost::lambda library in the following test code and I
found it difficult to parse/interpret what the code does in a sense how
a compiler parse/interpret it. For example, when both a compiler and I
see 'a=b+c' as assign the result of addition to a 3rd number in a
straightfoward maner but the lambda expressions are in a different
league. How does a compiler parse/interpret the lambda statements in
the following code? The comments are mine. Thanks for your help.
lambd uses a techinque of template metaprogramming called expression
templates to have the complier 'compute' a functor to execute the given
expression. Perhaps the pdf at
mrl.nyu.edu/~mkg/professional/programming/expr_templates.pdf
might explain the technique as it is a bit complicated for a newsgroup
message...
|
Thank you both for your links, they are actually identical articles in
different format. They did explain some of the techniques used behind
lambda.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|