1

Some simple code will demonstrate the problem:

class Foo {};
struct Bar {
    bool foo(const Foo &f) const { return false; }
};

int main() {
    Bar bar;

    vector<Foo> v;

    std::find_if(v.begin(), v.end(), std::bind1st(
        std::mem_fun_ref(&Bar::foo), bar));

    return 0;
}

Now, for this code, the VS2010 c++ compiler will complain: error C2535: bool std::binder1st<_Fn2>::operator()(const Foo&) const: member function already defined of declared

On earlier versions of Visual Studio, there would be two more compilation errors which are related to reference to reference issues. While these problems have gone in VS2010, the C2535 remains.

This question is similar to this one. As suggested by that post, i can use std::bind, or the boost library as alternatives. They work fine, but for now, i'd like to know is it possible to use the old bind1st style in this case, or is this problem more of a defect inherent in the STL functional framework? Thanks!

Community
  • 1
  • 1
weidi
  • 852
  • 7
  • 20

2 Answers2

3

This is not an issue of VS or any compiler. The type returned by mem_fun_ref is mem_fun_ref_t which inherits from unary function. This functor takes one argument which must be of the class type the member function belongs to. mem_fun_ref cannot work for member functions that take arguments.

The binders have been deprecated for a reason: They suck.

pmr
  • 58,701
  • 10
  • 113
  • 156
  • i think this is not true. `mem_fun_ref` has overloads for member functions that take one argument. Its return type is `const_mem_fun1_ref_t<_Result, _Ty, _Arg>`, which is a subtype of binary_function. For VS2010, they are defined in the header file – weidi Feb 08 '12 at 03:45
  • @weidi You can find the definition of `const_mem_fun_ref_t` in D8.2.2 in `[deprecated.member.pointer.adaptors]`. You are probably looking at a MSVC extension. I could not find any documentation for it on MSDN (not even for the header). – pmr Feb 08 '12 at 09:01
  • Is [this](http://msdn.microsoft.com/en-us/library/etctxx69(v=vs.100).aspx) the MSDN documentation? sorry if i have misunderstood that. i really don't know much about various c++ documents and i have no idea of what D8.2.2 refers to. Could you share the link in which the deprecation of adapters is mentioned? – weidi Feb 08 '12 at 10:53
0

Please take a look at Using bind1st for a method that takes argument by reference. It seems that it is the case similar to your case.

Community
  • 1
  • 1
  • thanks. that post doesn't provide a solution other than turning to C++11 or boost, which seems to support my opinion that there might be something inherently wrong with the design of bind1st. – weidi Feb 08 '12 at 10:38