Compilation difference between intel 9.0 and msvc 7.1 regarding const

I have code that will compile using msvc 7.1 but will not under intel 9.0. Here is some simplified code to illustrate my problem: using namespace boost; using namespace std; typedef array<int, 2> array_type; array_type a; a[0] = 0; a[1] = 1; vector<array_type> v; v.push_back(a); vector<int> h; for_each(v.begin(), v.end(), mem_fun_ref(&array_type::front)); This compiles and runs using msvc 7.1, but intel 9.0 errors with the following: error: more than one instance of overloaded function "mem_fun_ref" matches the argument list: function template "std::mem_fun_ref(_Result (_Ty::*)() const)" function template "std::mem_fun_ref(_Result (_Ty::*)())" argument types are: (<unknown-type>) Here are the two definitions of front for boost::array: reference front() { return elems[0]; } const_reference front() const { return elems[0]; } If I'm reading the error correctly, this means that the intel compiler doesn't know if I want to use the const or non-const version of front. Does anyone know anything about this? Is this the forwarding problem? Is a function wrapper around front a good solution? What are the solutions? Thanks, Chris

Chris Goller <goller@gmail.com> writes:
I have code that will compile using msvc 7.1 but will not under intel 9.0.
Here is some simplified code to illustrate my problem:
using namespace boost; using namespace std; typedef array<int, 2> array_type;
array_type a; a[0] = 0; a[1] = 1;
vector<array_type> v; v.push_back(a); vector<int> h;
for_each(v.begin(), v.end(), mem_fun_ref(&array_type::front));
This compiles and runs using msvc 7.1, but intel 9.0 errors with the following:
error: more than one instance of overloaded function "mem_fun_ref" matches the argument list: function template "std::mem_fun_ref(_Result (_Ty::*)() const)" function template "std::mem_fun_ref(_Result (_Ty::*)())" argument types are: (<unknown-type>)
Solution: Don't use std::mem_fun_ref Use boost::mem_fn instead. http://www.boost.org/libs/bind/mem_fn.html#Q1 HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com

On 11/30/05, David Abrahams <dave@boost-consulting.com> wrote:
Chris Goller <goller@gmail.com> writes:
I have code that will compile using msvc 7.1 but will not under intel 9.0.
Here is some simplified code to illustrate my problem:
using namespace boost; using namespace std; typedef array<int, 2> array_type;
array_type a; a[0] = 0; a[1] = 1;
vector<array_type> v; v.push_back(a); vector<int> h;
for_each(v.begin(), v.end(), mem_fun_ref(&array_type::front));
This compiles and runs using msvc 7.1, but intel 9.0 errors with the following:
error: more than one instance of overloaded function "mem_fun_ref" matches the argument list: function template "std::mem_fun_ref(_Result (_Ty::*)() const)" function template "std::mem_fun_ref(_Result (_Ty::*)())" argument types are: (<unknown-type>)
Solution:
Don't use std::mem_fun_ref Use boost::mem_fn instead.
http://www.boost.org/libs/bind/mem_fn.html#Q1
HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
Sadly, the same problem: works with msvc 7.1 put not intel 9.0: error: more than one instance of overloaded function "mem_fn" matches the argument list: function template "boost::mem_fn(R (T::*)() const)" function template "boost::mem_fn(R (T::*)())" argument types are: (<unknown-type>) This problem initially came up when I was using boost::bind in this way: make_transform_iterator(v.begin(), bind(&array_type::at, _1, 0)) Intel 9.0 had these errors: error: more than one instance of overloaded function "bind" matches the argument list: function template "boost::bind(R (T::*)(B1), A1, A2)" function template "boost::bind(R (T::*)(B1) const, A1, A2)" argument types are: (<unknown-type>, boost::arg<1>, int) Thanks, Chris

Chris Goller wrote:
Sadly, the same problem: works with msvc 7.1 put not intel 9.0:
error: more than one instance of overloaded function "mem_fn" matches the argument list: function template "boost::mem_fn(R (T::*)() const)" function template "boost::mem_fn(R (T::*)())" argument types are: (<unknown-type>)
This problem initially came up when I was using boost::bind in this way:
make_transform_iterator(v.begin(), bind(&array_type::at, _1, 0))
This is a bug in MSVC 7.1, I guess. You need to disambiguate: array_type::reference (array_type::* pmf) (array_type::size_type) = &array_type::at; make_transform_iterator( v.begin(), bind(pmf, _1, 0) ); Unfortunately, there is no way to tell from bind(&array_type::at, _1, 0) whether you need the const or non-const overload, and it is not possible to somehow store both overloads for later use.

On 11/30/05, Peter Dimov <pdimov@mmltd.net> wrote:
Chris Goller wrote:
Sadly, the same problem: works with msvc 7.1 put not intel 9.0:
error: more than one instance of overloaded function "mem_fn" matches the argument list: function template "boost::mem_fn(R (T::*)() const)" function template "boost::mem_fn(R (T::*)())" argument types are: (<unknown-type>)
This problem initially came up when I was using boost::bind in this way:
make_transform_iterator(v.begin(), bind(&array_type::at, _1, 0))
This is a bug in MSVC 7.1, I guess. You need to disambiguate:
array_type::reference (array_type::* pmf) (array_type::size_type) = &array_type::at;
make_transform_iterator( v.begin(), bind(pmf, _1, 0) );
Unfortunately, there is no way to tell from bind(&array_type::at, _1, 0) whether you need the const or non-const overload, and it is not possible to somehow store both overloads for later use.
Peter, thanks, you rock. I finally understand what is going on here. Is this a more elegant way? boost::make_transform_iterator(v.end(), bind(static_cast<array_type::reference (array_type::*) (array_type::size_type)>(&array_type::at), _1, 0)); Chris
participants (3)
-
Chris Goller
-
David Abrahams
-
Peter Dimov