Re: [Boost-users] [lambda] if-then-else construct gets broken bylambda-lib

-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Sebastian Weber Sent: Tuesday, November 07, 2006 12:41 PM To: boost-users@lists.boost.org Subject: [Boost-users] [lambda] if-then-else construct gets broken bylambda-lib
I'm trying to store a reference to a function depending upon a condition within a function object like this:
boost::function< double (std::size_t) > wf = (sIndex < m_maxIndex+1) ? ( boost::lambda::bind(boost::ref(m_cf), sDeg, boost::lambda::_1) ) : ( boost::ref(*m_wf) );
[Nat] Does it work better if the 'else' clause is something more like: ( boost::lambda::bind(boost::ref(*m_wf)) ) ? This is a wild guess, but boost::ref() isn't by itself a lambda bind expression -- is it? Both halves of the ternary operator are convertible to boost::function -- but they're not the same type. I don't know whether two different boost::lambda::bind expressions are going to be compatible either. You may have to explicitly instantiate boost::function objects on both sides of the : -- which would end up being less terse than writing the if/else statement. But it seems worth a try.

Hi Nat!
[Nat] Does it work better if the 'else' clause is something more like:
( boost::lambda::bind(boost::ref(*m_wf)) )
Well, not really. If I do that, I get the error.
error: no match for ternary 'operator?:' in '(sIndex <
(((boost::cor_cm_iterator4
? This is a wild guess, but boost::ref() isn't by itself a lambda bind expression -- is it? Both halves of the ternary operator are convertible to boost::function -- but they're not the same type.
I don't know whether two different boost::lambda::bind expressions are going to be compatible either. You may have to explicitly instantiate boost::function objects on both sides of the : -- which would end up being less terse than writing the if/else statement. But it seems worth a try.
I actually have no clue. Nevertheless, I'm already very happy to have written my first lambda-stuff without struggling to much with it - it is quite a magic thing to get it working for a beginner. Anyway thanks for your response. Greetings, Sebastian
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Nat Goodspeed
-
Sebastian Weber