boost.lambda problem

T

Tim H

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
boost::lambda::lambda_
functor_base<boost::lambda::eek:ther_action<boost::lambda::ifthenelsereturn_action>
, Args>::call(A&, B&, C&, Env&) const [with RET = const bignum&, A =
const bignu
m, B = const boost::tuples::null_type, C = const
boost::tuples::null_type, Env =
const boost::tuples::null_type, Args =
boost::tuples::tuple<boost::lambda::lamb
da_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<b
oost::lambda::equal_action>,
boost::tuples::tuple<boost::lambda::lambda_functor<
boost::lambda::placeholder<1> >, const int, boost::tuples::null_type,
boost::tup
les::null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuple
s::null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples:
:null_type> > >, const int,
boost::lambda::lambda_functor<boost::lambda::placeho
lder<1> >, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::nu
ll_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null
_type, boost::tuples::null_type>]':
/usr/include/boost/lambda/detail/lambda_functors.hpp:148:
instantiated from 't
ypename T::sig<boost::tuples::tuple<A&, boost::tuples::null_type,
boost::tuples:
:null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::n
ull_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::nul
l_type, boost::tuples::null_type> >::type
boost::lambda::lambda_functor<Base>::eek:
perator()(A&) const [with A = const bignum, T =
boost::lambda::lambda_functor_ba
se<boost::lambda::eek:ther_action<boost::lambda::ifthenelsereturn_action>,
boost::t
uples::tuple<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<bo
ost::lambda::relational_action<boost::lambda::equal_action>,
boost::tuples::tupl
e<boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, const
int, boos
t::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost:
:tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type, boost::t
uples::null_type, boost::tuples::null_type> > >, const int,
boost::lambda::lambd
a_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type,
boost::tupl
es::null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples
::null_type, boost::tuples::null_type, boost::tuples::null_type> >]'
.../pp_datatypes.h:454: instantiated from 'std::string
pp_transform_datatype<Td
efunc, Tenfunc>::evaluate(const pp_value&) const [with Tdefunc =
boost::lambda::
lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::eek:ther_action<bo
ost::lambda::ifthenelsereturn_action>,
boost::tuples::tuple<boost::lambda::lambd
a_functor<boost::lambda::lambda_functor_base<boost::lambda::relational_action<bo
ost::lambda::equal_action>,
boost::tuples::tuple<boost::lambda::lambda_functor<b
oost::lambda::placeholder<1> >, const int, boost::tuples::null_type,
boost::tupl
es::null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples
::null_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::
null_type> > >, const int,
boost::lambda::lambda_functor<boost::lambda::placehol
der<1> >, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::nul
l_type, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_
type, boost::tuples::null_type> > >, Tenfunc =
boost::lambda::lambda_functor<boo
st::lambda::lambda_functor_base<boost::lambda::arithmetic_action<boost::lambda::
minus_action>,
boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda:
:placeholder<1> >, const int, boost::tuples::null_type,
boost::tuples::null_type
, boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type,
boost::tuples::null_type, boost::tuples::null_type,
boost::tuples::null_type> >
cpuid/generic_device.cpp:419: instantiated from here
/usr/include/boost/lambda/if.hpp:315: warning: returning reference to
temporary
make[2]: *** [cpuid/generic_device.o] Error 1
make[1]: *** [devices] Error 2
make: *** [devices/all_devices.o] Error 2


cpuid/generic_device.cpp:419 is the last line of the file before the
final function's closing curly.

Changing the second _1 to an integer literal works.

I'm pretty much out of template-fu at this point...

Help?
 
K

kwikius

Tim H said:
cpuid/generic_device.cpp:419: instantiated from here
/usr/include/boost/lambda/if.hpp:315: warning: returning reference to
temporary
make[2]: *** [cpuid/generic_device.o] Error 1
make[1]: *** [devices] Error 2
make: *** [devices/all_devices.o] Error 2


cpuid/generic_device.cpp:419 is the last line of the file before the
final function's closing curly.

Changing the second _1 to an integer literal works.

I'm pretty much out of template-fu at this point...

Help?

You would get much better help on boost.org, but heres my 2.p's worth

Anyway the warning is pretty serious and shouldnt be ignored if you are
creating a temporary in some lambda function.
Maybe Investigate how the bignum semantics differs from the inbuilt int in
terms of copying and so on. Of course if its your own bignum then look at
premature optimisation. Are you returning by const cref as a hopeful
optimisation when you should be returning by value (e.g copying your
bignum)?

The other thing to try is (IIRC) to use one of the lambda mungwrappers to
try to enforce constness of your _1 arg.

IMO lambda's coolness factor is way higher than its usefulness ... ;-)

regards
Andy Little
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top