Hi all,
I'm having some difficulty in getting the following piece of code to
compile:
#include <iostream>
#include <deque>
#include <algorithm>
#include <boost/tuple/tuple.hpp>
#include <boost/lambda/lambda.hpp>
int main(void)
{
typedef boost::tuples::tuple<unsigned int, doublemy_tuple_type;
std::deque<my_tuple_typemy_list;
std::sort(my_list.begin(),my_list.end(),
(boost::lambda::_1).get<0>() <
(boost::lambda::_2).get<0>());
return 0;
}
my understanding of the lambda place-holders was that they represent
the value_type of the iterators in the above example. A simpler
example as below seems to work, just wondering why the above doesn't.
{
std::vector<intv_list;
std::sort(v_list.begin(),v_list.end(),
boost::lambda::_1 < boost::lambda::_2);
}
Jerzie 4 3127 Je**************@gmail.com wrote:
Hi all,
I'm having some difficulty in getting the following piece of code to
compile:
#include <iostream>
#include <deque>
#include <algorithm>
#include <boost/tuple/tuple.hpp>
#include <boost/lambda/lambda.hpp>
int main(void)
{
typedef boost::tuples::tuple<unsigned int, doublemy_tuple_type;
std::deque<my_tuple_typemy_list;
std::sort(my_list.begin(),my_list.end(),
(boost::lambda::_1).get<0>() <
(boost::lambda::_2).get<0>());
return 0;
}
my understanding of the lambda place-holders was that they represent
the value_type of the iterators in the above example. A simpler
example as below seems to work, just wondering why the above doesn't.
We cannot overload the dot-operator (what a shame!). Therefore, the magic
functor _1 cannot forward member functions.
You can try to use bind to make it work. So, instead of _1.get<0>, you would
have a monstrosity like:
bind( &whatever_type::get<0>, _1 )
(or worse: I did not try it.)
>
{
std::vector<intv_list;
std::sort(v_list.begin(),v_list.end(),
boost::lambda::_1 < boost::lambda::_2);
}
That works just fine because lambda does not run into limitations of the C++
core language (another thing that lambda cannot support elegantly is
some_vector[_1] since operator[] has to be a member function).
Best
Kai-Uwe Bux
Kai-Uwe Bux wrote:
We cannot overload the dot-operator (what a shame!). Therefore, the magic
functor _1 cannot forward member functions.
You can try to use bind to make it work. So, instead of _1.get<0>, you would
have a monstrosity like:
bind( &whatever_type::get<0>, _1 )
(or worse: I did not try it.)
What about the old trick
(*&_1).get<0>()
Normally this should work too. Of course, it implies that the operator&
of the object behind _1 is not overloaded in some magic way.
(I did not test it, since I have no boost::lambda currently running here.)
Marcel
The boost lambda library is wonderful in theory, but IMO a nightmare
in practice.
It's a seriously clever piece of software, and the authors should take
full credit for the ingenuity of it, but the time scale for using it
goes something like:
* for loop with iterators
* algorithm library with custom function object (or functional
library) ~ 2-3 times longer to program, similar performance as for
loop
* Boost Lambda library ~ a good 10 times longer than a for loop (if
ever) to program, significantly worse performance
I know it looks really nifty to have a bit of lambda in the code, but
I'm just curious to know if anyone has a compelling (non-academic)
reason to wrestle with the beast that is the BLL?
Brian
brian tyler <br*********@gmail.comwrites:
The boost lambda library is wonderful in theory, but IMO a nightmare
in practice.
It's a seriously clever piece of software, and the authors should take
full credit for the ingenuity of it, but the time scale for using it
goes something like:
* for loop with iterators
* algorithm library with custom function object (or functional
library) ~ 2-3 times longer to program, similar performance as for
loop
* Boost Lambda library ~ a good 10 times longer than a for loop (if
ever) to program, significantly worse performance
I know it looks really nifty to have a bit of lambda in the code, but
I'm just curious to know if anyone has a compelling (non-academic)
reason to wrestle with the beast that is the BLL?
Lisp envy?
Or otherwise, working with an IDE where creating a new function or
method is significantly more time consuming than just typing the
function signature in a text editor, and therefore where it would be
advantageous to be able to use anonymous functions.
--
__Pascal Bourguignon__ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen Thorne |
last post by:
Hi guys,
I'm a little worried about the expected disappearance of lambda in
python3000. I've had my brain badly broken by functional programming
in the past, and I would hate to see things...
|
by: Tom Anderson |
last post by:
Comrades,
During our current discussion of the fate of functional constructs in
python, someone brought up Guido's bull on the matter:
http://www.artima.com/weblogs/viewpost.jsp?thread=98196
...
|
by: talin at acm dot org |
last post by:
I've been reading about how "lambda" is going away in Python 3000 (or
at least, that's the stated intent), and while I agree for the most
part with the reasoning, at the same time I'd be sad to see...
|
by: Russell |
last post by:
I want my code to be Python 3000 compliant, and hear
that lambda is being eliminated. The problem is that I
want to partially bind an existing function with a value
"foo" that isn't known until...
|
by: Boris Borcic |
last post by:
>>x = (lambda : ((yield 666),(yield 777),(yield 888)))()
666
777
888
(None, None, None)
666
777
888
Traceback (most recent call last):
|
by: Jerzie.Klenchier |
last post by:
Hi all,
I'm having some difficulty in getting the following piece of code to
compile:
#include <iostream>
#include <deque>
#include <algorithm>
#include <boost/tuple/tuple.hpp>
#include...
|
by: I V |
last post by:
On Sun, 25 May 2008 13:43:15 +0200, Martin Manns wrote:
With Ivan's approach, you lose access to the actual lambdas, so you need
to create a new function and then modify its code object to...
|
by: Tim H |
last post by:
Compiling with g++ 4:
This line:
if_then_else_return(_1 == 0, 64, _1)
When called with a bignum class as an argument yields:
/usr/include/boost/lambda/if.hpp: In member function 'RET...
|
by: raylopez99 |
last post by:
Took a look at all the fuss about "lambda expressions" from Jon
Skeet's excellent book "C# in Depth". Jon has an example, reproduced
below (excerpt) on lambda expressions.
My n00b take: it's...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |