From: Thomas Geymayer Date: Sat, 13 Apr 2013 14:20:50 +0000 (+0200) Subject: Comparison operators for SGSharedPtr X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c83dae4c70d347d5e9131fe9a18c9b6e95d703c6;p=simgear.git Comparison operators for SGSharedPtr --- 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