[lambda][bind] trivial bind fails when lambda and bind are in the same source file

My environment is VC9 SP1 and Boost 1.35. This problem also occurs in boost 1.36. I had some code using lambda which worked fine for several weeks until today when someone else included my header in his code which used bind. He told me my code was broken but my tests ran fine. It took us a few minutes to find the problem and I've distilled it to this trivial reproducible case. #include <boost/bind.hpp> #include <boost/lambda/bind.hpp> void foo( int ) { } int main() { using namespace boost::lambda; bind( &foo, _1 ); } Compiling this gives: error C2872: '_1' : ambiguous symbol 1> could be 'c:\vfx\third_party\boost\1_35_0\boost\lambda\core.hpp(69) : boost::lambda::placeholder1_type &boost::lambda::`anonymous-namespace'::_1' 1> or 'c:\vfx\third_party\boost\1_35_0\boost\bind\placeholders.hpp(42) : boost::arg<I> `anonymous-namespace'::_1' 1> with 1> [ 1> I=1 1> ] I can make the problem go away by changing main to int main() { using boost::lambda::_1; using boost::lambda::bind; bind( &foo, _1 ); } but the actual code uses a lot more lambda and the amount of using directives I would need makes the code longer than rolling my own functor. I could also alias lambda to make main look something like int main() { namespace bll = boost::lambda; bll::bind( &foo, bll::_1 ); } but this introduces a lot of noise into the lambda expression and makes complex lambdas unreadable. Is this accepted behavior? Thanks, Michael Marcin

Michael Marcin: [ ::_1 vs bll::_1 ]
Is this accepted behavior?
It has been a source of complaints. Unfortunately a "proper fix" at this time will break all boost::bind-using code, so I've been reluctant to move the bind placeholders out of the way.

Peter Dimov <pdimov <at> pdimov.com> writes:
Michael Marcin:
[ ::_1 vs bll::_1 ]
Is this accepted behavior?
It has been a source of complaints. Unfortunately a "proper fix" at this time will break all boost::bind-using code, so I've been reluctant to move the bind placeholders out of the way.
We discussed this 5 years ago. AFAICR David Abrahams terminated the discussion tagging this as defect (http://osdir.com/ml/lib.boost.user/2003-01/msg00153.html) The trouble I had with ::_1 has a higher severity level than the breakage. I kindly ask you again to overcome your reluctance. Put a proper statement about the breaking change into the release notes and remove everything from global namespace. Also note that it is a good time to change this, since everybody ought to switch to std::tr1::bind anyway and boost::bind could be tagged as deprecated in favor of boost::tr1::bind. Markus

Markus Werle wrote:
Peter Dimov <pdimov <at> pdimov.com> writes:
Michael Marcin:
[ ::_1 vs bll::_1 ]
Is this accepted behavior? It has been a source of complaints. Unfortunately a "proper fix" at this time will break all boost::bind-using code, so I've been reluctant to move the bind placeholders out of the way.
We discussed this 5 years ago. AFAICR David Abrahams terminated the discussion tagging this as defect (http://osdir.com/ml/lib.boost.user/2003-01/msg00153.html)
The trouble I had with ::_1 has a higher severity level than the breakage. I kindly ask you again to overcome your reluctance. Put a proper statement about the breaking change into the release notes and remove everything from global namespace.
Also note that it is a good time to change this, since everybody ought to switch to std::tr1::bind anyway and boost::bind could be tagged as deprecated in favor of boost::tr1::bind.
Markus
Whoa!!! Does tr1::bind provide the relational operators that boost::bind does? We use these extensively throughout our production code. Jeff

Jeff Flinn <TriumphSprint2000 <at> hotmail.com> writes:
Whoa!!! Does tr1::bind provide the relational operators that boost::bind does? We use these extensively throughout our production code.
RTFM: (F stands for 'fine' in this case, and M for 'http://www.boost.org/doc/libs/1_35_0/doc/html/boost_tr1/subject_list.html'): // [6.1.3.5] relational operators template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator==(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator<(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator!=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator>(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator<=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator>=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); regards, Markus

Markus Werle wrote:
Jeff Flinn <TriumphSprint2000 <at> hotmail.com> writes:
Whoa!!! Does tr1::bind provide the relational operators that boost::bind does? We use these extensively throughout our production code.
RTFM: (F stands for 'fine' in this case, and M for 'http://www.boost.org/doc/libs/1_35_0/doc/html/boost_tr1/subject_list.html'):
// [6.1.3.5] relational operators template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator==(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator<(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator!=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator>(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator<=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&); template<class T1, class T2, ..., class TM, class U1, class U2, ..., class UM> bool operator>=(const tuple<T1, T2, ..., TM>&, const tuple<U1, U2, ..., UM>&);
I had read the Fine Manual, but I'm a little dense and don't see the relationship between the cited tuple relational operators and bind. ;-) Re-RTFM, I don't see any other mention of relational operators existing or not in regards to FUNTION OBJECT BINDERS. IIRC, Peter added the &&, || operators in may. Jeff
participants (4)
-
Jeff Flinn
-
Markus Werle
-
Michael Marcin
-
Peter Dimov