Hi, When trying to convert some code using boost::optional to using std::experimental::optional instead if come over the issue that I had to implement operator!= for the contained types.
When looking at n3793 it states that operator!= should be implemented with !(t1 == t2), and not t1 != t2 as the implementation in gcc 4.9 is doing. This is the case for both the operator!= implementation where optional<T> is compared against T. The other operators look ok, and only operator== and operator< are used in their implementations. Can this be fixed before 4.9? (changelog not done)
>From 6a93dcb458f055d94d13386ef68a39893327be84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= <lar...@gullik.org> Date: Sat, 29 Mar 2014 15:46:47 +0100 Subject: [PATCH] optional: implement operator!= in terms of operator== --- libstdc++-v3/include/experimental/optional | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/experimental/optional b/libstdc++-v3/include/experimental/optional index 5f2d93f..2a3f29d 100644 --- a/libstdc++-v3/include/experimental/optional +++ b/libstdc++-v3/include/experimental/optional @@ -736,12 +736,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp> constexpr bool operator!=(const optional<_Tp>& __lhs, _Tp const& __rhs) - { return !__lhs || *__lhs != __rhs; } + { return !__lhs || !(*__lhs == __rhs); } template<typename _Tp> constexpr bool operator!=(const _Tp& __lhs, const optional<_Tp>& __rhs) - { return !__rhs || __lhs != *__rhs; } + { return !__rhs || !(__lhs == *__rhs); } template<typename _Tp> constexpr bool -- 1.9.1.352.gd393d14
-- Lgb
_______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org https://lists.gnu.org/mailman/listinfo/help-gplusplus