From e32dfafbae37ff995f165f7195eb847eaf60254d Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 15 Aug 2015 13:15:44 +0300 Subject: [PATCH] First stab at fixing #55 --- libuavcan/include/uavcan/marshal/array.hpp | 11 +++++++++-- libuavcan/include/uavcan/util/templates.hpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libuavcan/include/uavcan/marshal/array.hpp b/libuavcan/include/uavcan/marshal/array.hpp index 9a51fb131e..3f112e4ce5 100644 --- a/libuavcan/include/uavcan/marshal/array.hpp +++ b/libuavcan/include/uavcan/marshal/array.hpp @@ -1085,16 +1085,23 @@ public: typedef SizeType size_type; }; +/** + * These operators will only be enabled if rhs and lhs are different types. This precondition allows to work-around + * the ambiguity arising from the scope containing two definitions: one here and the others in Array<>. + * Refer to https://github.com/UAVCAN/libuavcan/issues/55 for more info. + */ template UAVCAN_EXPORT -inline bool operator==(const R& rhs, const Array& lhs) +inline typename EnableIf >::Result, bool>::Type +operator==(const R& rhs, const Array& lhs) { return lhs.operator==(rhs); } template UAVCAN_EXPORT -inline bool operator!=(const R& rhs, const Array& lhs) +inline typename EnableIf >::Result, bool>::Type +operator!=(const R& rhs, const Array& lhs) { return lhs.operator!=(rhs); } diff --git a/libuavcan/include/uavcan/util/templates.hpp b/libuavcan/include/uavcan/util/templates.hpp index 9358a73f36..f842d4035f 100644 --- a/libuavcan/include/uavcan/util/templates.hpp +++ b/libuavcan/include/uavcan/util/templates.hpp @@ -91,6 +91,21 @@ struct UAVCAN_EXPORT Select typedef FalseType Result; }; +/** + * Checks if two identifiers refer to the same type. + */ +template +struct IsSameType +{ + enum { Result = 0 }; +}; + +template +struct IsSameType +{ + enum { Result = 1 }; +}; + /** * Remove reference as in */