Lets say I want to implement a smart pointer a_ptr
which can be compared with other smart pointers.
Then I need to implement all permutations of the comparison operators:
template<class T, class U>
bool operator==(const a_ptr<T>& a, const a_ptr<U>& b)
{
return a.get() == b.get();
}
template<class T, class U>
bool operator==(const std::shared_ptr<T>& a, const a_ptr<U>& b)
{
return a.get() == b.get();
}
template<class T, class U>
bool operator==(const a_ptr<T>& a, const std::shared_ptr<U>& b)
{
return a.get() == b.get();
}
and etc... for the rest of the operators.
Then maybe I would like to implement another smart pointer b_ptr
, which would give me 6 versions for every comparison operator (since I want it to also work with a_ptr
), clearly not manageable.
Is there any way to get around this problem?
EDIT:
I should have probably mentioned that I want to create wrappers around smart pointers, in which case this question makes more sense, e.g.
template<typename T>
class a_ptr
{
public:
const T* get() const {return p_.get();}
private:
std::shared_ptr<T> p_;
};
template<typename T>
class b_ptr
{
public:
const T* get() const {return p_.get();}
private:
a_ptr<T> p_;
};