This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Implementation of n3793 <experimental/optional>
- From: Luc Danton <lucdanton at free dot fr>
- To: libstdc++ at gcc dot gnu dot org
- Cc: jason at redhat dot com
- Date: Sat, 19 Oct 2013 03:42:34 +0200
- Subject: Re: [Patch] Implementation of n3793 <experimental/optional>
- Authentication-results: sourceware.org; auth=none
- References: <5260CFE7 dot 7000808 at free dot fr>
On 2013-10-18 08:06, Luc Danton wrote:
I'll provide those in a separate patch.
Here it is, which makes implementation of n3793 complete AFAICT. (To be
applied on top of the previous patch.)
>From 316d5551580bd232ac7699836a7d1a98c6789219 Mon Sep 17 00:00:00 2001
From: mickk <mickk@example.com>
Date: Sat, 19 Oct 2013 03:27:36 +0200
Subject: [PATCH] Added missing relops with affering tests.
---
libstdc++-v3/include/experimental/optional | 130 ++++++++++++++++++---
.../experimental/optional/constexpr/relops/1.cc | 15 +++
.../experimental/optional/constexpr/relops/2.cc | 27 +++++
.../experimental/optional/constexpr/relops/3.cc | 10 ++
.../experimental/optional/constexpr/relops/4.cc | 22 ++++
.../experimental/optional/constexpr/relops/5.cc | 17 ++-
.../experimental/optional/constexpr/relops/6.cc | 25 +++-
.../testsuite/experimental/optional/relops/1.cc | 15 +++
.../testsuite/experimental/optional/relops/2.cc | 27 +++++
.../testsuite/experimental/optional/relops/3.cc | 10 ++
.../testsuite/experimental/optional/relops/4.cc | 22 ++++
.../testsuite/experimental/optional/relops/5.cc | 17 ++-
.../testsuite/experimental/optional/relops/6.cc | 25 +++-
13 files changed, 327 insertions(+), 35 deletions(-)
diff --git a/libstdc++-v3/include/experimental/optional b/libstdc++-v3/include/experimental/optional
index 54cdc89..2811b01 100644
--- a/libstdc++-v3/include/experimental/optional
+++ b/libstdc++-v3/include/experimental/optional
@@ -633,7 +633,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
};
- // Comparisons between optional values.
+ // [X.Y.8] Comparisons between optional values.
template<typename _Tp>
constexpr bool
operator==(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
@@ -644,13 +644,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
constexpr bool
+ operator!=(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
+ { return !(__lhs == __rhs); }
+
+ template<typename _Tp>
+ constexpr bool
operator<(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
{
return static_cast<bool>(__rhs)
&& (!__lhs || *__lhs < *__rhs);
}
- // Comparisons with nullopt.
+ template<typename _Tp>
+ constexpr bool
+ operator>(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
+ { return __rhs < __lhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator<=(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
+ { return !(__rhs < __lhs); }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>=(const optional<_Tp>& __lhs, const optional<_Tp>& __rhs)
+ { return !(__lhs < __rhs); }
+
+ // [X.Y.9] Comparisons with nullopt.
template<typename _Tp>
constexpr bool
operator==(const optional<_Tp>& __lhs, nullopt_t) noexcept
@@ -663,6 +683,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
constexpr bool
+ operator!=(const optional<_Tp>& __lhs, nullopt_t) noexcept
+ { return static_cast<bool>(__lhs); }
+
+ template<typename _Tp>
+ constexpr bool
+ operator!=(nullopt_t, const optional<_Tp>& __rhs) noexcept
+ { return static_cast<bool>(__rhs); }
+
+ template<typename _Tp>
+ constexpr bool
operator<(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
{ return false; }
@@ -671,34 +701,96 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
operator<(nullopt_t, const optional<_Tp>& __rhs) noexcept
{ return static_cast<bool>(__rhs); }
- // Comparisons with value type.
template<typename _Tp>
constexpr bool
- operator==(const optional<_Tp>& __lhs, _Tp const& __rhs)
- {
- return __lhs && *__lhs == __rhs;
- }
+ operator>(const optional<_Tp>& __lhs, nullopt_t) noexcept
+ { return static_cast<bool>(__lhs); }
template<typename _Tp>
constexpr bool
- operator==(_Tp const& __lhs, const optional<_Tp>& __rhs)
- {
- return __rhs && __lhs == *__rhs;
- }
+ operator>(nullopt_t, const optional<_Tp>& /* __rhs */) noexcept
+ { return false; }
template<typename _Tp>
constexpr bool
- operator<(const optional<_Tp>& __lhs, _Tp const& __rhs)
- {
- return !__lhs || *__lhs < __rhs;
- }
+ operator<=(const optional<_Tp>& __lhs, nullopt_t) noexcept
+ { return !__lhs; }
template<typename _Tp>
constexpr bool
- operator<(_Tp const& __lhs, const optional<_Tp>& __rhs)
- {
- return __rhs && __lhs < *__rhs;
- }
+ operator<=(nullopt_t, const optional<_Tp>& /* __rhs */) noexcept
+ { return true; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>=(const optional<_Tp>& /* __lhs */, nullopt_t) noexcept
+ { return true; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>=(nullopt_t, const optional<_Tp>& __rhs) noexcept
+ { return !__rhs; }
+
+ // [X.Y.10] Comparisons with value type.
+ template<typename _Tp>
+ constexpr bool
+ operator==(const optional<_Tp>& __lhs, const _Tp& __rhs)
+ { return __lhs && *__lhs == __rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator==(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return __rhs && __lhs == *__rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator!=(const optional<_Tp>& __lhs, _Tp const& __rhs)
+ { return !__lhs || *__lhs != __rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator!=(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return !__rhs || __lhs != *__rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator<(const optional<_Tp>& __lhs, const _Tp& __rhs)
+ { return !__lhs || *__lhs < __rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator<(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return __rhs && __lhs < *__rhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>(const optional<_Tp>& __lhs, const _Tp& __rhs)
+ { return __lhs && __rhs < *__lhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return !__rhs || *__rhs < __lhs; }
+
+ template<typename _Tp>
+ constexpr bool
+ operator<=(const optional<_Tp>& __lhs, const _Tp& __rhs)
+ { return !__lhs || !(__rhs < *__lhs); }
+
+ template<typename _Tp>
+ constexpr bool
+ operator<=(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return __rhs && !(*__rhs < __lhs); }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>=(const optional<_Tp>& __lhs, const _Tp& __rhs)
+ { return __lhs && !(*__lhs < __rhs); }
+
+ template<typename _Tp>
+ constexpr bool
+ operator>=(const _Tp& __lhs, const optional<_Tp>& __rhs)
+ { return !__rhs || !(__lhs < *__rhs); }
// [X.Y.11]
template<typename _Tp>
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc
index 131a6de..591eb13 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -60,25 +64,36 @@ int main()
{
constexpr O o, p;
static_assert( o == p, "" );
+ static_assert( !(o != p), "" );
}
{
constexpr O o { value_type { 42, "forty-two" } }, p;
static_assert( !(o == p), "" );
+ static_assert( o != p, "" );
}
{
constexpr O o, p { value_type { 42, "forty-two" } };
static_assert( !(o == p), "" );
+ static_assert( o != p, "" );
}
{
constexpr O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } };
static_assert( !(o == p), "" );
+ static_assert( o != p, "" );
+ }
+
+ {
+ constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } };
+ static_assert( !(o == p), "" );
+ static_assert( o != p, "" );
}
{
constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } };
static_assert( o == p, "" );
+ static_assert( !(o != p), "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc
index b0ae27a..9bc140d 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -60,25 +64,48 @@ int main()
{
constexpr O o, p;
static_assert( !(o < p), "" );
+ static_assert( !(o > p), "" );
+ static_assert( o <= p, "" );
+ static_assert( o >= p, "" );
}
{
constexpr O o { value_type { 42, "forty-two" } }, p;
static_assert( !(o < p), "" );
+ static_assert( o > p, "" );
+ static_assert( !(o <= p), "" );
+ static_assert( o >= p, "" );
}
{
constexpr O o, p { value_type { 42, "forty-two" } };
static_assert( o < p, "" );
+ static_assert( !(o > p), "" );
+ static_assert( o <= p, "" );
+ static_assert( !(o >= p), "" );
}
{
constexpr O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } };
static_assert( o < p, "" );
+ static_assert( !(o > p), "" );
+ static_assert( o <= p, "" );
+ static_assert( !(o >= p), "" );
+ }
+
+ {
+ constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } };
+ static_assert( !(o < p), "" );
+ static_assert( o > p, "" );
+ static_assert( !(o <= p), "" );
+ static_assert( o >= p, "" );
}
{
constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } };
static_assert( !(o < p), "" );
+ static_assert( !(o > p), "" );
+ static_assert( o <= p, "" );
+ static_assert( o >= p, "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc
index 23e332b..6ffd2b6 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -63,17 +67,23 @@ int main()
constexpr O o;
static_assert( !(o == reference), "" );
static_assert( !(reference == o), "" );
+ static_assert( o != reference, "" );
+ static_assert( reference != o, "" );
}
{
constexpr O o { value_type { 11, "eleventy" } };
static_assert( !(o == reference), "" );
static_assert( !(reference == o), "" );
+ static_assert( o != reference, "" );
+ static_assert( reference != o, "" );
}
{
constexpr O o { value_type { 42, "forty-two" } };
static_assert( o == reference, "" );
static_assert( reference == o, "" );
+ static_assert( !(o != reference), "" );
+ static_assert( !(reference != o), "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc
index ab99264..8df602c 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -63,17 +67,35 @@ int main()
constexpr O o;
static_assert( o < reference, "" );
static_assert( !(reference < o), "" );
+ static_assert( !(o > reference), "" );
+ static_assert( reference > o, "" );
+ static_assert( o <= reference, "" );
+ static_assert( !(reference <= o), "" );
+ static_assert( !(o >= reference), "" );
+ static_assert( reference >= o, "" );
}
{
constexpr O o { value_type { 11, "eleventy" } };
static_assert( o < reference, "" );
static_assert( !(reference < o), "" );
+ static_assert( !(o > reference), "" );
+ static_assert( reference > o, "" );
+ static_assert( o <= reference, "" );
+ static_assert( !(reference <= o), "" );
+ static_assert( !(o >= reference), "" );
+ static_assert( reference >= o, "" );
}
{
constexpr O o { value_type { 42, "forty-two" } };
static_assert( !(o < reference), "" );
static_assert( !(reference < o), "" );
+ static_assert( !(o > reference), "" );
+ static_assert( !(reference > o), "" );
+ static_assert( o <= reference, "" );
+ static_assert( reference <= o, "" );
+ static_assert( o >= reference, "" );
+ static_assert( reference >= o, "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc
index db95470..241a71b 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -56,16 +60,21 @@ int main()
{
using ns::value_type;
using O = std::experimental::optional<value_type>;
+ using std::experimental::nullopt;
{
constexpr O o;
- static_assert( o == std::experimental::nullopt, "" );
- static_assert( std::experimental::nullopt == o, "" );
+ static_assert( o == nullopt, "" );
+ static_assert( nullopt == o, "" );
+ static_assert( !(o != nullopt), "" );
+ static_assert( !(nullopt != o), "" );
}
{
constexpr O o { std::experimental::in_place };
- static_assert( !(o == std::experimental::nullopt), "" );
- static_assert( !(std::experimental::nullopt == o), "" );
+ static_assert( !(o == nullopt), "" );
+ static_assert( !(nullopt == o), "" );
+ static_assert( o != nullopt, "" );
+ static_assert( nullopt != o, "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc
index 1da2c85..a4282d8 100644
--- a/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc
@@ -47,6 +47,10 @@ namespace ns
{ return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); }
constexpr bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ constexpr bool
operator<(value_type const& lhs, value_type const& rhs)
{ return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); }
@@ -56,16 +60,29 @@ int main()
{
using ns::value_type;
using O = std::experimental::optional<value_type>;
+ using std::experimental::nullopt;
{
constexpr O o;
- static_assert( !(o < std::experimental::nullopt), "" );
- static_assert( !(std::experimental::nullopt < o), "" );
+ static_assert( !(o < nullopt), "" );
+ static_assert( !(nullopt < o), "" );
+ static_assert( !(o > nullopt), "" );
+ static_assert( !(nullopt > o), "" );
+ static_assert( o <= nullopt, "" );
+ static_assert( nullopt <= o, "" );
+ static_assert( o >= nullopt, "" );
+ static_assert( nullopt >= o, "" );
}
{
constexpr O o { std::experimental::in_place };
- static_assert( !(o < std::experimental::nullopt), "" );
- static_assert( std::experimental::nullopt < o, "" );
+ static_assert( !(o < nullopt), "" );
+ static_assert( nullopt < o, "" );
+ static_assert( o > nullopt, "" );
+ static_assert( !(nullopt > o), "" );
+ static_assert( !(o <= nullopt), "" );
+ static_assert( nullopt <= o, "" );
+ static_assert( o >= nullopt, "" );
+ static_assert( !(nullopt >= o), "" );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/1.cc b/libstdc++-v3/testsuite/experimental/optional/relops/1.cc
index 45db6d7..6f0c60f 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/1.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/1.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -50,25 +54,36 @@ int main()
{
O o, p;
VERIFY( o == p );
+ VERIFY( !(o != p) );
}
{
O o { value_type { 42, "forty-two" } }, p;
VERIFY( !(o == p) );
+ VERIFY( o != p );
}
{
O o, p { value_type { 42, "forty-two" } };
VERIFY( !(o == p) );
+ VERIFY( o != p );
}
{
O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } };
VERIFY( !(o == p) );
+ VERIFY( o != p );
+ }
+
+ {
+ O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } };
+ VERIFY( !(o == p) );
+ VERIFY( o != p );
}
{
O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } };
VERIFY( o == p );
+ VERIFY( !(o != p) );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/2.cc b/libstdc++-v3/testsuite/experimental/optional/relops/2.cc
index dfbb66e..b1ae705 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/2.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/2.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -50,25 +54,48 @@ int main()
{
O o, p;
VERIFY( !(o < p) );
+ VERIFY( !(o > p) );
+ VERIFY( o <= p );
+ VERIFY( o >= p );
}
{
O o { value_type { 42, "forty-two" } }, p;
VERIFY( !(o < p) );
+ VERIFY( o > p );
+ VERIFY( !(o <= p) );
+ VERIFY( o >= p );
}
{
O o, p { value_type { 42, "forty-two" } };
VERIFY( o < p );
+ VERIFY( !(o > p) );
+ VERIFY( o <= p );
+ VERIFY( !(o >= p) );
}
{
O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } };
VERIFY( o < p );
+ VERIFY( !(o > p) );
+ VERIFY( o <= p );
+ VERIFY( !(o >= p) );
+ }
+
+ {
+ O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } };
+ VERIFY( !(o < p) );
+ VERIFY( o > p );
+ VERIFY( !(o <= p) );
+ VERIFY( o >= p );
}
{
O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } };
VERIFY( !(o < p) );
+ VERIFY( !(o > p) );
+ VERIFY( o <= p );
+ VERIFY( o >= p );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/3.cc b/libstdc++-v3/testsuite/experimental/optional/relops/3.cc
index b7fc84d..6b361df 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/3.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/3.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -53,17 +57,23 @@ int main()
O o;
VERIFY( !(o == reference) );
VERIFY( !(reference == o) );
+ VERIFY( o != reference );
+ VERIFY( reference != o );
}
{
O o { value_type { 11, "eleventy" } };
VERIFY( !(o == reference) );
VERIFY( !(reference == o) );
+ VERIFY( o != reference );
+ VERIFY( reference != o );
}
{
O o { value_type { 42, "forty-two" } };
VERIFY( o == reference );
VERIFY( reference == o );
+ VERIFY( !(o != reference) );
+ VERIFY( !(reference != o) );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/4.cc b/libstdc++-v3/testsuite/experimental/optional/relops/4.cc
index b285339..9f316f1 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/4.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/4.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -53,17 +57,35 @@ int main()
O o;
VERIFY( o < reference );
VERIFY( !(reference < o) );
+ VERIFY( !(o > reference) );
+ VERIFY( reference > o );
+ VERIFY( o <= reference );
+ VERIFY( !(reference <= o) );
+ VERIFY( !(o >= reference) );
+ VERIFY( reference >= o );
}
{
O o { value_type { 11, "eleventy" } };
VERIFY( o < reference );
VERIFY( !(reference < o) );
+ VERIFY( !(o > reference) );
+ VERIFY( reference > o );
+ VERIFY( o <= reference );
+ VERIFY( !(reference <= o) );
+ VERIFY( !(o >= reference) );
+ VERIFY( reference >= o );
}
{
O o { value_type { 42, "forty-two" } };
VERIFY( !(o < reference) );
VERIFY( !(reference < o) );
+ VERIFY( !(o > reference) );
+ VERIFY( !(reference > o) );
+ VERIFY( o <= reference );
+ VERIFY( reference <= o );
+ VERIFY( o >= reference );
+ VERIFY( reference >= o );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/5.cc b/libstdc++-v3/testsuite/experimental/optional/relops/5.cc
index 1519076..c7b27bb 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/5.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/5.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -46,16 +50,21 @@ int main()
{
using ns::value_type;
using O = std::experimental::optional<value_type>;
+ using std::experimental::nullopt;
{
O o;
- VERIFY( o == std::experimental::nullopt );
- VERIFY( std::experimental::nullopt == o );
+ VERIFY( o == nullopt );
+ VERIFY( nullopt == o );
+ VERIFY( !(o != nullopt) );
+ VERIFY( !(nullopt != o) );
}
{
O o { std::experimental::in_place };
- VERIFY( !(o == std::experimental::nullopt) );
- VERIFY( !(std::experimental::nullopt == o) );
+ VERIFY( !(o == nullopt) );
+ VERIFY( !(nullopt == o) );
+ VERIFY( o != nullopt );
+ VERIFY( nullopt != o );
}
}
diff --git a/libstdc++-v3/testsuite/experimental/optional/relops/6.cc b/libstdc++-v3/testsuite/experimental/optional/relops/6.cc
index c94c4e7..d8a4f6f 100644
--- a/libstdc++-v3/testsuite/experimental/optional/relops/6.cc
+++ b/libstdc++-v3/testsuite/experimental/optional/relops/6.cc
@@ -37,6 +37,10 @@ namespace ns
{ return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); }
bool
+ operator!=(value_type const& lhs, value_type const& rhs)
+ { return !(lhs == rhs); }
+
+ bool
operator<(value_type const& lhs, value_type const& rhs)
{ return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); }
@@ -46,16 +50,29 @@ int main()
{
using ns::value_type;
using O = std::experimental::optional<value_type>;
+ using std::experimental::nullopt;
{
O o;
- VERIFY( !(o < std::experimental::nullopt) );
- VERIFY( !(std::experimental::nullopt < o) );
+ VERIFY( !(o < nullopt) );
+ VERIFY( !(nullopt < o) );
+ VERIFY( !(o > nullopt) );
+ VERIFY( !(nullopt > o) );
+ VERIFY( o <= nullopt );
+ VERIFY( nullopt <= o );
+ VERIFY( o >= nullopt );
+ VERIFY( nullopt >= o );
}
{
O o { std::experimental::in_place };
- VERIFY( !(o < std::experimental::nullopt) );
- VERIFY( std::experimental::nullopt < o );
+ VERIFY( !(o < nullopt) );
+ VERIFY( nullopt < o );
+ VERIFY( o > nullopt );
+ VERIFY( !(nullopt > o) );
+ VERIFY( !(o <= nullopt) );
+ VERIFY( nullopt <= o );
+ VERIFY( o >= nullopt );
+ VERIFY( !(nullopt >= o) );
}
}
--
1.8.1.2