Created attachment 26913 [details] Example code that fails The following simple code doesn't compile: #include <tr1/functional> int return_int2(int,int) { return 42; } int main(){ std::tr1::bind(return_int2,32,std::tr1::placeholders::_1)(5); } Compiler output: $g++ t2.cpp t2.cpp: In function ‘int main()’: t2.cpp:9:64: error: no match for call to ‘(std::tr1::_Bind<int (*(int, std::tr1::_Placeholder<1>))(int, int)>) (int)’ /usr/include/c++/4.6/tr1/functional:1134:11: note: candidates are: /usr/include/c++/4.6/tr1/functional:1205:9: note: typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int] /usr/include/c++/4.6/tr1/functional:1205:9: note: no known conversion for argument 1 from ‘int’ to ‘int&’ /usr/include/c++/4.6/tr1/functional:1216:9: note: typename std::tr1::result_of<const _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) const [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<const _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int] /usr/include/c++/4.6/tr1/functional:1216:9: note: no known conversion for argument 1 from ‘int’ to ‘int&’ /usr/include/c++/4.6/tr1/functional:1228:9: note: typename std::tr1::result_of<volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) volatile [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int] /usr/include/c++/4.6/tr1/functional:1228:9: note: no known conversion for argument 1 from ‘int’ to ‘int&’ /usr/include/c++/4.6/tr1/functional:1241:9: note: typename std::tr1::result_of<const volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) const volatile [with _Args = {int}, _Functor = int (*)(int, int), _Bound_args = {int, std::tr1::_Placeholder<1>}, typename std::tr1::result_of<const volatile _Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type = int] /usr/include/c++/4.6/tr1/functional:1241:9: note: no known conversion for argument 1 from ‘int’ to ‘int&’ $ g++ --version g++ (Ubuntu 4.6.0-3~ppa1) 4.6.1 20110409 (prerelease) Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I seem to remember that this is a known problem of the tr1 version of this facility, per the specs. Changing the snippet like the following works: ... int main() { int n = 5; std::tr1::bind(return_int2,32,std::tr1::placeholders::_1)(n); }
See my comments on PR 50320 C++11 std::bind works with rvalues, as of GCC 4.5 *** This bug has been marked as a duplicate of bug 35569 ***
It's frustrating that the TR1 spec specifies lvalues (I assumed it was the same as std::bind). This came up in supposedly-portable code that works with MSVC's TR1 bind. Good thing it's fixed for std::bind.
Yeah, it's not ideal, but I have very little motivation (and even less time!) to improve tr1::bind now. For C++03 code there's boost::bind and for C++11 code there's std::bind.