comeau reports no error, and with stlport5 testcase works fine. $ g++ -I/usr/include/stlport main.cpp -o main -lstlport && ./main Hello 1 Hello 2 with libstdc++ i get: $ g++ main.cpp -o main && ./main /usr/include/c++/4.1.2/bits/stl_function.h: In instantiation of ‘std::binder2nd<std::pointer_to_binary_function<int, const std::string&, void> >’: main.cpp:13: instantiated from here /usr/include/c++/4.1.2/bits/stl_function.h:435: error: forming reference to reference type ‘const std::string&’ /usr/include/c++/4.1.2/bits/stl_function.h: In function ‘std::binder2nd<_Operation> std::bind2nd(const _Operation&, const _Tp&) [with _Operation = std::pointer_to_binary_function<int, const std::string&, void>, _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’: main.cpp:13: instantiated from here /usr/include/c++/4.1.2/bits/stl_function.h:455: error: no matching function for call to ‘std::binder2nd<std::pointer_to_binary_function<int, const std::string&, void> >::binder2nd(const std::pointer_to_binary_function<int, const std::string&, void>&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’ /usr/include/c++/4.1.2/bits/stl_function.h:429: note: candidates are: std::binder2nd<std::pointer_to_binary_function<int, const std::string&, void> >::binder2nd(const std::binder2nd<std::pointer_to_binary_function<int, const std::string&, void> >&)
Created attachment 12461 [details] testcase
This is a well knows issue with the current standard binders, see, for example: http://gcc.gnu.org/ml/libstdc++/2000-06/msg00210.html It is possible to extend the implementation, but the real way to go is moving to the new generalized bind facility, which will be in C++0x and we are already providing as part of our tr1 delivery. It would be (modulo tr1 namespace decorations...): bind(std::ptr_fun( print ), _1, str)
Actually this is valid C++ via DR 106. Reopening to ...
To close as a dup of bug 7412. *** This bug has been marked as a duplicate of 7412 ***
Ah, interesting! Therefore, if I understand correctly DR 106, when the C++ front-end will implement the resolution, this kind of bind2nd usage will magically start working without changing at all the library... On the other hand, Bjarne' observation in DR 106 is also interesting, because maintains that the library is mainly at fault for the binders... and this is already fixed in tr1::bind! Making progress everywhere!