[boost.lambda] Problem with combining if_then_else_return and bind?
Hi - I've been trying to use the if_then_else_return feature of
Boost.Lambda, and have run into a problem using Lambda's bind with
this feature. My minimal example (at the end of the message) fails
when compiled with the VC7.1 command line "cl -c -EHsc -DBAD" (the
-DBAD is to compile the non-compiling code). The error message
(attached as err.txt) indicates that return type deduction has failed
at some point, I guess. The compiling version of the code differs from
the non-compiling version by assigning the bind result to a variable.
This seems to enable correct return type deduction. No other forms
using lambda and bind that I've tried have exhibited this problem. So,
the question is - is this a bug in Lambda or am I doing something
wrong?
Oh, I've also tried this with gcc 3.4.2 (Mingw version) and it behaved
the same as VC7.1.
Stuart Dootson
#include
Hello Stuart, Thanks for submitting a full program to try immediately. It seem to be a bug in Lambda, the type deduction gives bool for the type of the first branch, and const bool& for the second. And deems that both are convertible to each other and claims it's ambiguous. Best, Jaakko Järvi You should get an error in the compiler, On Sep 1, 2005, at 4:32 AM, Stuart Dootson wrote:
Hi - I've been trying to use the if_then_else_return feature of Boost.Lambda, and have run into a problem using Lambda's bind with this feature. My minimal example (at the end of the message) fails when compiled with the VC7.1 command line "cl -c -EHsc -DBAD" (the -DBAD is to compile the non-compiling code). The error message (attached as err.txt) indicates that return type deduction has failed at some point, I guess. The compiling version of the code differs from the non-compiling version by assigning the bind result to a variable. This seems to enable correct return type deduction. No other forms using lambda and bind that I've tried have exhibited this problem. So, the question is - is this a bug in Lambda or am I doing something wrong?
Oh, I've also tried this with gcc 3.4.2 (Mingw version) and it behaved the same as VC7.1.
Stuart Dootson
#include
#include #include #include using namespace boost::lambda; bool Test1(char);
void Fn(char c, bool b) { bool flag; #if defined(BAD) boost::function
fn = if_then_else_return(var(b), bind<bool>(&Test1, _1), constant(false) ) ; #else bool blah; boost::function fn = if_then_else_return(var(b), var(blah)=bind(&Test1, _1), constant(false) ) ; #endif } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- Jaakko Järvi, Assistant Professor -- Texas A&M University, Computer Science -- jarvi@cs.tamu.edu
On 9/1/05, jarvi
Hello Stuart,
Thanks for submitting a full program to try immediately.
It seem to be a bug in Lambda, the type deduction gives bool for the type of the first branch, and const bool& for the second. And deems that both are convertible to each other and claims it's ambiguous.
Best,
Jaakko Järvi
Thanks for the quick reply - it's prompted me to try using const bool
rather than bool for the bind return type:
boost::function
participants (2)
-
jarvi
-
Stuart Dootson