From c83dae4c70d347d5e9131fe9a18c9b6e95d703c6 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 13 Apr 2013 16:20:50 +0200 Subject: [PATCH] Comparison operators for SGSharedPtr --- simgear/structure/SGSharedPtr.hxx | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/simgear/structure/SGSharedPtr.hxx b/simgear/structure/SGSharedPtr.hxx index 479c1972..081d5eb9 100644 --- a/simgear/structure/SGSharedPtr.hxx +++ b/simgear/structure/SGSharedPtr.hxx @@ -132,4 +132,42 @@ SGSharedPtr static_pointer_cast(SGSharedPtr const & r) { return SGSharedPtr( static_cast(r.get()) ); } + +/** + * Compare two SGSharedPtr objects for equality. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + */ +template +bool operator==(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() == rhs.get(); +} + +/** + * Compare two SGSharedPtr objects for equality. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + */ +template +bool operator!=(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() != rhs.get(); +} + +/** + * Compare two SGSharedPtr objects for weak ordering. + * + * @note Only pointer values are compared, not the actual objects they are + * pointing at. + * @note This allows using SGSharedPtr as key in associative containers like for + * example std::map and std::set. + */ +template +bool operator<(const SGSharedPtr& lhs, const SGSharedPtr& rhs) +{ + return lhs.get() < rhs.get(); +} #endif -- 2.39.5