#4566 closed Bugs (fixed)
Binding to a class member with lambda::bind() can cause const qualifier mismatch.
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | To Be Determined | Component: | lambda |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The following code (omitting namespaces) would compile correctly in Boost 1.43.0, but now fails with error boost/lambda/detail/function_adaptors.hpp(264) : error C2440 : 'return' : cannot convert from 'const int' to 'int &:
bind( &pair<int,int>::first, _1 )( make_pair( 1, 0 ) );
The boost::lambda::bind()
expression creates a function that returns the first element of a pair, and then applies this to a const pair<int,int>
. The following will work, because the argument is not constant:
pair<int,int> x(1,0); bind( &pair<int,int>::first, _1 )( x );
A workaround for this issue is to specify the return value of bind()
explicitly, but it shouldn't be necessary for this simple case:
bind<int>( &pair<int,int>::first, _1 )( make_pair( 1, 0 ) );
I have tested this on VC8 and VC10 with identical results.
Thanks for a great library,
/David
Attachments (1)
Change History (4)
by , 12 years ago
Attachment: | lambda.cpp added |
---|
comment:1 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Repro case