Add models of shared_ptr comparison operators

Reviewed By: jvillard

Differential Revision: D3534300

fbshipit-source-id: a95ecf4
master
Andrzej Kotulski 9 years ago committed by Facebook Github Bot 2
parent 046654a9c0
commit 9cda4ca6bf

@ -214,6 +214,102 @@ class shared_ptr : public std__shared_ptr<T> {
return true; /* FIXME - use non-det */
}
};
template <class _Tp, class _Up>
inline bool operator==(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
return __x.get() == __y.get();
}
template <class _Tp, class _Up>
inline bool operator!=(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
return !(__x == __y);
}
template <class _Tp, class _Up>
inline bool operator<(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
typedef typename common_type<_Tp*, _Up*>::type _Vp;
return less<_Vp>()(__x.get(), __y.get());
}
template <class _Tp, class _Up>
inline bool operator>(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
return __y < __x;
}
template <class _Tp, class _Up>
inline bool operator<=(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
return !(__y < __x);
}
template <class _Tp, class _Up>
inline bool operator>=(const shared_ptr<_Tp>& __x,
const shared_ptr<_Up>& __y) noexcept {
return !(__x < __y);
}
template <class _Tp>
inline bool operator==(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return !__x;
}
template <class _Tp>
inline bool operator==(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return !__x;
}
template <class _Tp>
inline bool operator!=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return static_cast<bool>(__x);
}
template <class _Tp>
inline bool operator!=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return static_cast<bool>(__x);
}
template <class _Tp>
inline bool operator<(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return less<_Tp*>()(__x.get(), nullptr);
}
template <class _Tp>
inline bool operator<(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return less<_Tp*>()(nullptr, __x.get());
}
template <class _Tp>
inline bool operator>(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return nullptr < __x;
}
template <class _Tp>
inline bool operator>(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return __x < nullptr;
}
template <class _Tp>
inline bool operator<=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return !(nullptr < __x);
}
template <class _Tp>
inline bool operator<=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return !(__x < nullptr);
}
template <class _Tp>
inline bool operator>=(const shared_ptr<_Tp>& __x, nullptr_t) noexcept {
return !(__x < nullptr);
}
template <class _Tp>
inline bool operator>=(nullptr_t, const shared_ptr<_Tp>& __x) noexcept {
return !(nullptr < __x);
}
template <class T>
struct hash<shared_ptr<T>> : public hash<std__shared_ptr<T>> {};

@ -107,3 +107,23 @@ int shared_ptr_move_null_deref() {
std::shared_ptr<int> p2 = std::move(p1);
return *p1;
}
int shared_ptr_check_null() {
std::shared_ptr<int> p;
if (p == nullptr)
return 1;
return *p;
}
int shared_ptr_check_notnull() {
std::shared_ptr<int> p;
if (p != nullptr)
return *p;
return 1;
}
int shared_ptr_check_null2(std::shared_ptr<int> p) {
if (p == nullptr)
return 1;
return *p;
}

Loading…
Cancel
Save