Boost logo

Boost :

From: Christian Bach (bach_at_[hidden])
Date: 2000-07-25 04:22:26


hi

i have encountered a problem concerning operator != in the boost
shared_ptr template.
it collides with the standard library defined != operator of stl_relops
when used in the following manner:

#include <iostream>
#include <vector>
#include <algorithm>
#include "boost/smart_ptr.hpp"

using std::vector;
using std::find;
using boost::shared_ptr;

class Test {
};

int main(int argc, char *argv[]) {
    shared_ptr<Test> firstTest (new Test());
    shared_ptr<Test> secondTest (new Test());

    vector< shared_ptr<Test> > v;
    v.push_back(firstTest);
    v.push_back(secondTest);
    
    vector< shared_ptr<Test> >::iterator pos;
    pos = find(v.begin(), v.end(), firstTest);
    if (pos != v.end()) v.erase(pos);

    return 0;
}

i'm using g++
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

when commenting out the lines

template<typename T, typename U>
 inline bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b)
    { return a.get() != b.get(); }

in the shared_ptr template everthing seems to work just fine (hopefully !)

what do you think ? is it safe commenting out the above lines ?
do we need those lines ? or are there other possibilities to circumvent
the problem ?

cheers

christian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk