Boost logo

Boost Users :

From: Kirit Sælensminde (kirit.saelensminde_at_[hidden])
Date: 2007-07-11 12:54:47


I'm trying to really understand the limits of what can be done in C++
with Boost.Function and Boost.Lambda by implementing a number of
functional programming idioms in C++.

I've done a few fairly complicated things, but seem to have run into a
problem with a really basic one. I just want to do a partial application
on some basic operands.

This is what I'm trying to do:

boost::function< int( int ) > increment( boost::lambda::_1 + 1 );

This gives an error that operator + isn't defined for the Boost
placeholder type. If I add the following it works:

template< typename V >
V add( V l, V r ) {
        return l + r;
}
template< typename S >
boost::function< S ( S ) > operator +( const
boost::lambda::placeholder1_type, S s ) {
        return boost::lambda::bind( add< S >, boost::lambda::_1, s );
}

I guess there's a huge number of these that could (should?) be added. Is
this an oversight, or am I doing things with the library that I'm not
meant to do?

I'm using MSVC 7.1 and Boost 1.34.0 release candidate.

K


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