By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,825 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,825 IT Pros & Developers. It's quick & easy.

boost.lambda problem

P: n/a
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::other_action<boost::la mbda::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<boos t::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::place ho
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>::o
perator()(A&) const [with A = const bignum, T =
boost::lambda::lambda_functor_ba
se<boost::lambda::other_action<boost::lambda::ifth enelsereturn_action>,
boost::t
uples::tuple<boost::lambda::lambda_functor<boost:: lambda::lambda_functor_base<bo
ost::lambda::relational_action<boost::lambda::equa l_action>,
boost::tuples::tupl
e<boost::lambda::lambda_functor<boost::lambda::pla ceholder<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::other_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::place hol
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::ari thmetic_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?
Aug 1 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Tim H" <th*****@gmail.comwrote in message
news:f5**********************************@h17g2000 prg.googlegroups.com...
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

Aug 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.