Skip to content

Commit ae2f794

Browse files
Merge pull request #1485 from AnyOldName3/observer_ptr-comparison
observer_ptr comparison improvements
2 parents 8f5dee2 + 08522ad commit ae2f794

1 file changed

Lines changed: 57 additions & 6 deletions

File tree

include/vsg/core/observer_ptr.h

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,73 @@ namespace vsg
9797
}
9898

9999
template<class R>
100-
bool operator<(const observer_ptr<R>& rhs) const { return (rhs._ptr < _ptr); }
100+
bool operator<(const observer_ptr<R>& rhs) const { return (rhs._ptr < _ptr) || (rhs._ptr == _ptr && rhs._auxiliary < _auxiliary); }
101101

102102
template<class R>
103-
bool operator==(const observer_ptr<R>& rhs) const { return (rhs._ptr == _ptr); }
103+
bool operator==(const observer_ptr<R>& rhs) const { return (rhs._auxiliary == _auxiliary); }
104104

105105
template<class R>
106-
bool operator!=(const observer_ptr<R>& rhs) const { return (rhs._ptr != _ptr); }
106+
bool operator!=(const observer_ptr<R>& rhs) const { return (rhs._auxiliary != _auxiliary); }
107107

108108
template<class R>
109-
bool operator<(const R* rhs) const { return (rhs < _ptr); }
109+
bool operator<(const R* rhs) const
110+
{
111+
if (rhs < _ptr)
112+
return true;
113+
if (_ptr == nullptr)
114+
return false;
115+
return rhs->getAuxiliary() < _auxiliary;
116+
}
117+
118+
template<class R>
119+
bool operator==(const R* rhs) const
120+
{
121+
if (rhs != _ptr)
122+
return false;
123+
if (rhs == nullptr)
124+
return true;
125+
return rhs->getAuxiliary() == _auxiliary;
126+
}
127+
128+
template<class R>
129+
bool operator!=(const R* rhs) const
130+
{
131+
if (rhs != _ptr)
132+
return true;
133+
if (rhs == nullptr)
134+
return false;
135+
return rhs->getAuxiliary() != _auxiliary;
136+
}
110137

111138
template<class R>
112-
bool operator==(const R* rhs) const { return (rhs == _ptr); }
139+
bool operator<(const vsg::ref_ptr<R> rhs) const
140+
{
141+
if (rhs.get() < _ptr)
142+
return true;
143+
if (_ptr == nullptr)
144+
return false;
145+
return rhs->getAuxiliary() < _auxiliary;
146+
}
113147

114148
template<class R>
115-
bool operator!=(const R* rhs) const { return (rhs != _ptr); }
149+
bool operator==(const vsg::ref_ptr<R> rhs) const
150+
{
151+
if (rhs.get() != _ptr)
152+
return false;
153+
if (rhs == nullptr)
154+
return true;
155+
return rhs->getAuxiliary() == _auxiliary;
156+
}
157+
158+
template<class R>
159+
bool operator!=(const vsg::ref_ptr<R> rhs) const
160+
{
161+
if (rhs.get() != _ptr)
162+
return true;
163+
if (rhs == nullptr)
164+
return false;
165+
return rhs->getAuxiliary() != _auxiliary;
166+
}
116167

117168
bool valid() const noexcept { return _auxiliary.valid() && _auxiliary->getConnectedObject() != nullptr; }
118169

0 commit comments

Comments
 (0)