0
votes

I have a problem. Why can't I compile this? What is wrong?

#include <boost/iterator/indirect_iterator.hpp>

bool finder(std::list<SomeObject*>::const_iterator first, 
        std::list<SomeObject*>::const_iterator last, 
        const SomeObject& x) 
{
   return std::find(boost::make_indirect_iterator(first),
                    boost::make_indirect_iterator(last),
                    x) != boost::make_indirect_iterator(last); 
}

// This code is from answer to my previous post

I have errors like:

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\algorithm(40) : error C2784: 'bool std::operator ==(const _Ty &,const std::complex<_Other> &)' : could not deduce template argument for 'const std::complex<_Other> &' from 'const SomeObject

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\algorithm(40) : error C2784: 'bool std::operator ==(const std::complex<_Other> &,const _Ty &)' : could not deduce template argument for 'const std::complex<_Other> &' from 'SomeObject'

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include\algorithm(40) : error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from SomeObject

and several similar errors..

I have defined operator==:

bool operator==(const SomeObject& x, const SomeObject& y)
{
    return x.id1() == y.id1();
}

I use VS 2005.

How to fix it? What is wrong? Maybe it's VS2005 bug? Can You compile this?

1

1 Answers

1
votes

It means *advance(boost::make_indirect_iterator(first), some_int) can not be passed to operator == which accepts const SomeObject&. And this is strange.

One suggestion would be to keep bool operator== inside namespace std.

namespace std {
  bool operator==(const SomeObject& x, const SomeObject& y)
  {
    return x.id1() == y.id1();
  }
}