Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 1999-11-10 13:08:40


ivan66_at_[hidden] wrote:
>> I assume that it would be legal to compare a shared_ptr<Derived> with a
>> shared_ptr<Base>? Also, that a shared_array<Base> could be compared to
>> a shared_array<Base>,

Valentin Bonnard wrote:
> It depends on the declaration of op== (member or non member).
>
> 1) member: conversions allowed on rhs but not lhs
> => base == derived passes
> but derived == base fails
> => very strange dissymmetric effect
>
> 2) non member: no conversions at all
> => symmetry in that base == derived and derived == base
> both fail the same way

Isn't it possible to have a non-member template function version of operator
== with two class parameters which would make both base == derived and
derived == base work?

Something like this (I probably got details wrong):

    template <class T, class U>
    bool operator==(const shared_ptr<T>& left, const shared_ptr<U>& right)
    {
        return left.get() == right.get();
    }

    -- Darin


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