|
Boost : |
From: ivan66_at_[hidden]
Date: 1999-11-10 14:01:30
darin adler <dari-_at_[hidden]> wrote:
original article:http://www.egroups.com/group/boost/?start=926
> 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
Yes. It should probably be declared inline, BTW. You could do
something similar with a member template, e.g.:
template <class T> class shared_ptr
{
//...
template <class U>
bool operator==(const shared_ptr<U>& right)
{
return get() == right.get();
}
};
For shared_array, the non-member version would be something like
template <class T>
inline bool operator==(const shared_ptr<T>& left,
const shared_ptr<T>& right)
{
return left.get() == right.get();
}
and the member version would be an ordinary (non-template) member
function.
Offhand, I don't see any compelling argument either way for the member
vs. non-member versions. The non-member version does allow explicit
specialization, but I'm pretty well convinced that specialization would
be a bad idea anyway. Does anyone see a good reason to go one way or
the other?
-- Ivan J. Johnson
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk