T
Tron Thomas
Given the following code:
#include <vector>
#include <algorithm>
#include <functional>
class Value
{
public:
explicit Value(int value) : m_value(value) {}
void ChangeTo(int value) { m_value = value; }
private:
int m_value;
};
int main()
{
std::vector<Value> values;
values.insert(values.end(), 5, Value(6));
std::for_each(values.begin(), values.end(),
std::bind2nd(std::mem_fun_ref(&Value::ChangeTo), 7));
return 0;
}
Under two different compiler, the code compiles without any warnings
or errors. A third compiler produces an error with output like the
following:
error: 'std::mem_fun1_ref_t<void,class Value,int>:perator`()'' :
cannot convert parameter 1 from 'const
std::binder2nd<_Fn2>::argument_type' to 'Value &' with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
Conversion loses qualifiers while compiling class-template member
function 'std::binder2nd<_Fn2>::result_type
std::binder2nd<_Fn2>:perator ()(const
std::binder2nd<_Fn2>::argument_type &) const' with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
see reference to class template instantiation 'std::binder2nd<_Fn2>'
being compiled with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
Is this a valid error?
What can I do to fix the problem?
#include <vector>
#include <algorithm>
#include <functional>
class Value
{
public:
explicit Value(int value) : m_value(value) {}
void ChangeTo(int value) { m_value = value; }
private:
int m_value;
};
int main()
{
std::vector<Value> values;
values.insert(values.end(), 5, Value(6));
std::for_each(values.begin(), values.end(),
std::bind2nd(std::mem_fun_ref(&Value::ChangeTo), 7));
return 0;
}
Under two different compiler, the code compiles without any warnings
or errors. A third compiler produces an error with output like the
following:
error: 'std::mem_fun1_ref_t<void,class Value,int>:perator`()'' :
cannot convert parameter 1 from 'const
std::binder2nd<_Fn2>::argument_type' to 'Value &' with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
Conversion loses qualifiers while compiling class-template member
function 'std::binder2nd<_Fn2>::result_type
std::binder2nd<_Fn2>:perator ()(const
std::binder2nd<_Fn2>::argument_type &) const' with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
see reference to class template instantiation 'std::binder2nd<_Fn2>'
being compiled with
[
_Fn2=std::mem_fun1_ref_t<void,Value,int>
]
Is this a valid error?
What can I do to fix the problem?