Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2000-07-25 20:43:38

on 7/25/00 2:22 AM, Christian Bach at bach_at_[hidden] wrote:

> 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:

I believe this problem is due to a non-standard-conforming library
implementatoin. The relops template functions should only be searched if you
do "using namespace std::rel_ops;" or "using std::rel_ops::operator !=;".

> 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 !)

It's OK to make that change locally as a workaround for the problem, but not
in the master copy of the header.

> what do you think ? is it safe commenting out the above lines ?

Besides the fact that they need to be included explicitly on
standard-conforming compiler/libraries, there are at least two problems with
the std::rel_ops function templates.

    1) Since they are not in same namespace as the shared_ptr class
templates, Koenig lookup does not guarantee that they will be found.
    2) They work only if the left and right are the same class, so you can't
compare shared_ptr<Derived> with shared_ptr<Base> like you can with the
shared_ptr versoins.

> do we need those lines ? or are there other possibilities to circumvent
> the problem ?

I'm not sure why your library includes the relops function templates
unconditionally, nor am I sure how the multiple applicable function
templates interact in your configuration or even how they are suppose to
interact in a standard-conforming implementation.

Perhaps we can do some conditional compilation to omit the != function
template from smart_ptr.hpp for your broken compiler/library.

    -- Darin

Boost list run by bdawes at, gregod at, cpdaniel at, john at