Patchwork std::experimental::optional operator!=

login
register
mail settings
Submitter Lars Gullik =?iso-8859-1?Q?Bj=F8nnes?=
Date March 30, 2014, 10:54 a.m.
Message ID <m3r45kc5ya.fsf@black.gullik.net>
Download mbox | patch
Permalink /patch/335096/
State New
Headers show

Comments

Lars Gullik =?iso-8859-1?Q?Bj=F8nnes?= - March 30, 2014, 10:54 a.m.
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)

Patch

From 6a93dcb458f055d94d13386ef68a39893327be84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= <larsbj@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