Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-07-23 19:50:58


David Abrahams wrote:

>>>> It might be easier to just make it work by adding the appropriate A
>>>> const& overloads to lambda_functor, as we did with boost::bind.

...

> Well, then, I would go for that. But we'd have to get someone who
> knows BLL to do the work ;-)

Yeah.

Patch:

Index: lambda_functors.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/lambda/detail/lambda_functors.hpp,v
retrieving revision 1.8
diff -u -r1.8 lambda_functors.hpp
--- lambda_functors.hpp 6 Jul 2006 13:47:26 -0000 1.8
+++ lambda_functors.hpp 23 Jul 2007 23:44:39 -0000
@@ -148,6 +148,14 @@
>(a, cnull_type(), cnull_type(), cnull_type());
   }

+ template<class A>
+ typename inherited::template sig<tuple<A const&> >::type
+ operator()(A const& a) const {
+ return inherited::template call<
+ typename inherited::template sig<tuple<A const&> >::type
+ >(a, cnull_type(), cnull_type(), cnull_type());
+ }
+
   template<class A, class B>
   typename inherited::template sig<tuple<A&, B&> >::type
   operator()(A& a, B& b) const {
@@ -156,6 +164,30 @@
>(a, b, cnull_type(), cnull_type());
   }

+ template<class A, class B>
+ typename inherited::template sig<tuple<A const&, B&> >::type
+ operator()(A const& a, B& b) const {
+ return inherited::template call<
+ typename inherited::template sig<tuple<A const&, B&> >::type
+ >(a, b, cnull_type(), cnull_type());
+ }
+
+ template<class A, class B>
+ typename inherited::template sig<tuple<A&, B const&> >::type
+ operator()(A& a, B const& b) const {
+ return inherited::template call<
+ typename inherited::template sig<tuple<A&, B const&> >::type
+ >(a, b, cnull_type(), cnull_type());
+ }
+
+ template<class A, class B>
+ typename inherited::template sig<tuple<A const&, B const&> >::type
+ operator()(A const& a, B const& b) const {
+ return inherited::template call<
+ typename inherited::template sig<tuple<A const&, B const&> >::type
+ >(a, b, cnull_type(), cnull_type());
+ }
+
   template<class A, class B, class C>
   typename inherited::template sig<tuple<A&, B&, C&> >::type
   operator()(A& a, B& b, C& c) const
@@ -165,6 +197,15 @@
>(a, b, c, cnull_type());
   }

+ template<class A, class B, class C>
+ typename inherited::template sig<tuple<A const&, B const&, C const&>
>::type
+ operator()(A const& a, B const& b, C const& c) const
+ {
+ return inherited::template call<
+ typename inherited::template sig<tuple<A const&, B const&, C const&>
>::type
+ >(a, b, c, cnull_type());
+ }
+
   // for internal calls with env
   template<CALL_TEMPLATE_ARGS>
   typename inherited::template sig<tuple<CALL_REFERENCE_TYPES> >::type

Test:

#include <boost/lambda/lambda.hpp>
#include <boost/detail/lightweight_test.hpp>

int main()
{
    using namespace boost::lambda;

    int x = 0;
    int const y = 1;
    int const z = 2;

    BOOST_TEST( _1( x ) == 0 );
    BOOST_TEST( _1( y ) == 1 );
    BOOST_TEST( _1( 2 ) == 2 );

    BOOST_TEST( _2( x, x ) == 0 );
    BOOST_TEST( _2( x, y ) == 1 );
    BOOST_TEST( _2( x, 2 ) == 2 );

    BOOST_TEST( _2( 4, x ) == 0 );
    BOOST_TEST( _2( 4, y ) == 1 );
    BOOST_TEST( _2( 4, 2 ) == 2 );

    (_1 = _2)( x, y );
    BOOST_TEST( x == y );

    (_1 = _2)( x, 3 );
    BOOST_TEST( x == 3 );

    (_2 = _1)( z, x );
    BOOST_TEST( x == z );

    (_2 = _1)( 4, x );
    BOOST_TEST( x == 4 );

    BOOST_TEST( _3( x, x, x ) == x );
    BOOST_TEST( _3( x, x, y ) == y );
    BOOST_TEST( _3( x, x, 2 ) == 2 );

    BOOST_TEST( _3( x, 5, x ) == x );
    BOOST_TEST( _3( x, 5, y ) == y );
    BOOST_TEST( _3( x, 5, 2 ) == 2 );

    BOOST_TEST( _3( 9, 5, x ) == x );
    BOOST_TEST( _3( 9, 5, y ) == y );
    BOOST_TEST( _3( 9, 5, 2 ) == 2 );

    return boost::report_errors();
}


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