Boost logo

Boost Users :

Subject: [Boost-users] Bind and overloaded operators in Visual Studio 2008
From: Benjamin Swerts (Ben.Swerts_at_[hidden])
Date: 2008-11-12 10:30:17


Hello everyone,

This is my first post to this list so apologies in advance for all the
rules I will be breaking.

I have a problem using overloaded operators in Visual Studio 2008 SP1 (no
feature pack installed) with Boost version 1.36.0. The following code
works perfectly in Visual Studio 2005:

//////////
#include <algorithm>
#include <functional>
#include <vector>
struct Foo
{
  Foo(unsigned int first, unsigned int second)
    : first_(first), second_(second){};
  unsigned int first_;
  unsigned int second_;
};
int main(int, char*)
{
  std::vector<Foo> v(10, Foo(1, 2));
  const unsigned int test = 1;
  std::find_if(v.begin(), v.end(),
               std::tr1::bind( std::equal_to<unsigned int>(),
                               std::tr1::bind(&Foo::first_,
std::tr1::placeholders::_1),
                               test));
  std::find_if(v.begin(), v.end(), std::tr1::bind( &Foo::first_,
std::tr1::placeholders::_1 ) == test );
  return 0;
}
//////////

The 2 find_if calls have the exact same behaviour. If I compile this with
2008, I get the following errors for the second find_if call:

.\main.cpp(19) : error C2784: 'bool std::tr1::operator
==(std::tr1::_Unutterable,const std::tr1::function<_Fty> &)' : could not
deduce template argument for 'const std::tr1::function<_Fty> &' from
'const unsigned int'
        C:\Program Files\Microsoft Visual Studio
9.0\VC\include\../include/functional(1100) : see declaration of
'std::tr1::operator =='
.\main.cpp(19) : error C2784: 'bool std::tr1::operator ==(const
std::tr1::function<_Fty> &,std::tr1::_Unutterable)' : could not deduce
template argument for 'const std::tr1::function<_Fty> &' from
'std::tr1::_Bind<_Ret,_BindN>'
        with
        [
            _Ret=std::tr1::_Notforced,
            _BindN=std::tr1::_Bind1,std::tr1::_Ph<1>>
        ]
        C:\Program Files\Microsoft Visual Studio
9.0\VC\include\../include/functional(1094) : see declaration of
'std::tr1::operator =='
.\main.cpp(19) : error C2784: 'bool std::tr1::operator ==(const
std::tr1::shared_ptr<_Ty> &,const std::tr1::shared_ptr<_Ty2> &)' : could
not deduce template argument for 'const std::tr1::shared_ptr<_Ty> &' from
'std::tr1::_Bind<_Ret,_BindN>'
        with
        [
            _Ret=std::tr1::_Notforced,
            _BindN=std::tr1::_Bind1,std::tr1::_Ph<1>>
        ]
        C:\Program Files\Microsoft Visual Studio
9.0\VC\include\../include/memory(1598) : see declaration of
'std::tr1::operator =='
.\main.cpp(19) : error C2676: binary '==' : 'std::tr1::_Bind<_Ret,_BindN>'
does not define this operator or a conversion to a type acceptable to the
predefined operator
        with
        [
            _Ret=std::tr1::_Notforced,
            _BindN=std::tr1::_Bind1,std::tr1::_Ph<1>>
        ]

I have honestly no idea what I should do to fix this. Mailing list and
google searches turned up nothing so any help would be much appreciated.

TIA,

        Ben

-------------------------
Ben Swerts
Software engineer
ICOS Vision Systems NV
-------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net