bind1st fails to compile when argument type is a constant reference
Jonathan Wakely
jwakely.gcc@gmail.com
Sat Nov 19 12:11:00 GMT 2011
2011/11/19 Jonathan Wakely:
> 2011/11/19 Krzysztof Żelechowski:
>>
>> I did read the issue. It is still open, the fix is a suggested fix, there
>> are arguments against the fix on reflector which I do not have access to so
>> I do not know whether the arguments are the same as the mine. The fix is
>> required by Stroustrup's book, not by the standard. If removing it would
>> break existing code, it is possible to guard it as an optional fragment with
>> a macro.
The post on the reflector is quoted below. It doesn't argue for
removing the overload, and it wasn't done and what we've implemented
is what was voted into the standard.
c++std-lib-9127:
Consider this code:
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
struct X : binary_function<int, int, void>
{
void operator () (int arg, int val)
{
cout << arg << " " << val << endl;
}
};
int main()
{
vector<int> v(5, 2);
for_each(v.begin(), v.end(), bind2nd(X(), 3));
return 0;
}
This fails to compile under the current resolution of 109. The compiler
attempts to call the new binder2nd::operator() that is overloaded on
int& (as opposed to const int&), but since this method is const, it
fails to call X::operator() because /that/ method is non-const. I
believe that the intent of issue 109 is for code like this to work. I
propose that the const be removed from the new operator() overloads in
issue 109.
More information about the Libstdc++
mailing list