From 4ad67e08cbc1470f9b288b9c2d873d9c5d18fe0f Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 9 Dec 2014 14:49:17 +0000 Subject: [PATCH] Add all the relational operators to std::experimental::optional. Also update bad_optional_access to match the Library Fundamentals draft standard. This is not all of the upcoming changes to optional, though. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@223775 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/experimental/optional | 407 +++++++++++++----- src/optional.cpp | 5 +- .../char_pointer.pass.cpp | 29 -- .../copy_assign.pass.cpp | 35 -- .../copy_ctor.pass.cpp | 32 -- .../default.pass.cpp | 5 +- .../string.pass.cpp | 29 -- .../optional.comp_with_t/equal.pass.cpp | 16 +- .../optional.comp_with_t/greater.pass.cpp | 61 +++ .../greater_equal.pass.cpp | 61 +++ .../optional.comp_with_t/less_equal.pass.cpp | 61 +++ .../optional.comp_with_t/less_than.pass.cpp | 24 +- .../optional.comp_with_t/not_equal.pass.cpp | 58 +++ .../{eqaul.pass.cpp => equal.pass.cpp} | 4 +- .../optional.nullops/greater.pass.cpp | 41 ++ .../optional.nullops/greater_equal.pass.cpp | 41 ++ .../optional.nullops/less_equal.pass.cpp | 41 ++ .../optional.nullops/less_than.pass.cpp | 2 +- .../optional.nullops/not_equal.pass.cpp | 41 ++ .../optional.relops/greater_equal.pass.cpp | 75 ++++ .../optional.relops/greater_than.pass.cpp | 75 ++++ .../optional.relops/less_equal.pass.cpp | 75 ++++ .../optional.relops/less_than.pass.cpp | 16 +- .../optional.relops/not_equal.pass.cpp | 79 ++++ 24 files changed, 1047 insertions(+), 266 deletions(-) delete mode 100644 test/utilities/optional/optional.bad_optional_access/char_pointer.pass.cpp delete mode 100644 test/utilities/optional/optional.bad_optional_access/copy_assign.pass.cpp delete mode 100644 test/utilities/optional/optional.bad_optional_access/copy_ctor.pass.cpp delete mode 100644 test/utilities/optional/optional.bad_optional_access/string.pass.cpp create mode 100644 test/utilities/optional/optional.comp_with_t/greater.pass.cpp create mode 100644 test/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp create mode 100644 test/utilities/optional/optional.comp_with_t/less_equal.pass.cpp create mode 100644 test/utilities/optional/optional.comp_with_t/not_equal.pass.cpp rename test/utilities/optional/optional.nullops/{eqaul.pass.cpp => equal.pass.cpp} (92%) create mode 100644 test/utilities/optional/optional.nullops/greater.pass.cpp create mode 100644 test/utilities/optional/optional.nullops/greater_equal.pass.cpp create mode 100644 test/utilities/optional/optional.nullops/less_equal.pass.cpp create mode 100644 test/utilities/optional/optional.nullops/not_equal.pass.cpp create mode 100644 test/utilities/optional/optional.relops/greater_equal.pass.cpp create mode 100644 test/utilities/optional/optional.relops/greater_than.pass.cpp create mode 100644 test/utilities/optional/optional.relops/less_equal.pass.cpp create mode 100644 test/utilities/optional/optional.relops/not_equal.pass.cpp diff --git a/include/experimental/optional b/include/experimental/optional index 2f0df35db..a384882a1 100644 --- a/include/experimental/optional +++ b/include/experimental/optional @@ -16,131 +16,147 @@ // C++1y -#include +namespace std { namespace experimental { inline namespace fundamentals_v1 { -namespace std { namespace experimental { + // 5.3, optional for object types + template class optional; -// optional for object types -template -class optional -{ -public: - typedef T value_type; + // 5.4, In-place construction + struct in_place_t{}; + constexpr in_place_t in_place{}; - // constructors - constexpr optional() noexcept; - constexpr optional(nullopt_t) noexcept; - optional(const optional&); - optional(optional&&) noexcept(is_nothrow_move_constructible::value); - constexpr optional(const T&); - constexpr optional(T&&); - template constexpr explicit optional(in_place_t, Args&&...); - template - constexpr explicit optional(in_place_t, initializer_list, Args&&...); + // 5.5, No-value state indicator + struct nullopt_t{see below}; + constexpr nullopt_t nullopt(unspecified); - // destructor - ~optional(); + // 5.6, Class bad_optional_access + class bad_optional_access; - // assignment - optional& operator=(nullopt_t) noexcept; - optional& operator=(const optional&); - optional& operator=(optional&&) - noexcept(is_nothrow_move_assignable::value && - is_nothrow_move_constructible::value); - template optional& operator=(U&&); - template void emplace(Args&&...); - template void emplace(initializer_list, Args&&...); + // 5.7, Relational operators + template + constexpr bool operator==(const optional&, const optional&); + template + constexpr bool operator!=(const optional&, const optional&); + template + constexpr bool operator<(const optional&, const optional&); + template + constexpr bool operator>(const optional&, const optional&); + template + constexpr bool operator<=(const optional&, const optional&); + template + constexpr bool operator>=(const optional&, const optional&); - // swap - void swap(optional&) - noexcept(is_nothrow_move_constructible::value && - noexcept(swap(declval(), declval()))); + // 5.8, Comparison with nullopt + template constexpr bool operator==(const optional&, nullopt_t) noexcept; + template constexpr bool operator==(nullopt_t, const optional&) noexcept; + template constexpr bool operator!=(const optional&, nullopt_t) noexcept; + template constexpr bool operator!=(nullopt_t, const optional&) noexcept; + template constexpr bool operator<(const optional&, nullopt_t) noexcept; + template constexpr bool operator<(nullopt_t, const optional&) noexcept; + template constexpr bool operator<=(const optional&, nullopt_t) noexcept; + template constexpr bool operator<=(nullopt_t, const optional&) noexcept; + template constexpr bool operator>(const optional&, nullopt_t) noexcept; + template constexpr bool operator>(nullopt_t, const optional&) noexcept; + template constexpr bool operator>=(const optional&, nullopt_t) noexcept; + template constexpr bool operator>=(nullopt_t, const optional&) noexcept; - // observers - constexpr T const* operator->() const; - T* operator->(); - constexpr T const& operator*() const; - T& operator*(); - constexpr explicit operator bool() const noexcept; - constexpr T const& value() const; - T& value(); - template constexpr T value_or(U&&) const&; - template T value_or(U&&) &&; -}; + // 5.9, Comparison with T + template constexpr bool operator==(const optional&, const T&); + template constexpr bool operator==(const T&, const optional&); + template constexpr bool operator!=(const optional&, const T&); + template constexpr bool operator!=(const T&, const optional&); + template constexpr bool operator<(const optional&, const T&); + template constexpr bool operator<(const T&, const optional&); + template constexpr bool operator<=(const optional&, const T&); + template constexpr bool operator<=(const T&, const optional&); + template constexpr bool operator>(const optional&, const T&); + template constexpr bool operator>(const T&, const optional&); + template constexpr bool operator>=(const optional&, const T&); + template constexpr bool operator>=(const T&, const optional&); -// In-place construction -struct in_place_t{}; -constexpr in_place_t in_place{}; + // 5.10, Specialized algorithms + template void swap(optional&, optional&) noexcept(see below); + template constexpr optional make_optional(T&&); -// Disengaged state indicator -struct nullopt_t{see below}; -constexpr nullopt_t nullopt(unspecified); + template + class optional + { + public: + typedef T value_type; -// class bad_optional_access -class bad_optional_access - : public logic_error -{ -public: - explicit bad_optional_access(const string& what_arg); - explicit bad_optional_access(const char* what_arg); -}; + // 5.3.1, Constructors + constexpr optional() noexcept; + constexpr optional(nullopt_t) noexcept; + optional(const optional&); + optional(optional&&) noexcept(see below); + constexpr optional(const T&); + constexpr optional(T&&); + template constexpr explicit optional(in_place_t, Args&&...); + template + constexpr explicit optional(in_place_t, initializer_list, Args&&...); -// Relational operators -template constexpr bool operator==(const optional&, const optional&); -template constexpr bool operator< (const optional&, const optional&); + // 5.3.2, Destructor + ~optional(); -// Comparison with nullopt -template constexpr bool operator==(const optional&, nullopt_t) noexcept; -template constexpr bool operator==(nullopt_t, const optional&) noexcept; -template constexpr bool operator<(const optional&, nullopt_t) noexcept; -template constexpr bool operator<(nullopt_t, const optional&) noexcept; + // 5.3.3, Assignment + optional& operator=(nullopt_t) noexcept; + optional& operator=(const optional&); + optional& operator=(optional&&) noexcept(see below); + template optional& operator=(U&&); + template void emplace(Args&&...); + template + void emplace(initializer_list, Args&&...); -// Comparison with T -template constexpr bool operator==(const optional&, const T&); -template constexpr bool operator==(const T&, const optional&); -template constexpr bool operator<(const optional&, const T&); -template constexpr bool operator<(const T&, const optional&); + // 5.3.4, Swap + void swap(optional&) noexcept(see below); -// Specialized algorithms -template void swap(optional&, optional&) noexcept(see below); -template constexpr optional::type> make_optional(T&&); + // 5.3.5, Observers + constexpr T const* operator ->() const; + constexpr T* operator ->(); + constexpr T const& operator *() const &; + constexpr T& operator *() &; + constexpr T&& operator *() &&; + constexpr const T&& operator *() const &&; + constexpr explicit operator bool() const noexcept; + constexpr T const& value() const &; + constexpr T& value() &; + constexpr T&& value() &&; + constexpr const T&& value() const &&; + template constexpr T value_or(U&&) const &; + template constexpr T value_or(U&&) &&; -// hash support -template struct hash; -template struct hash>; + private: + T* val; // exposition only + }; -}} // std::experimental + } // namespace fundamentals_v1 + } // namespace experimental + + // 5.11, Hash support + template struct hash; + template struct hash>; + +} // namespace std */ -#include <__config> +#include #include #include -namespace std { namespace experimental { - +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL class _LIBCPP_EXCEPTION_ABI bad_optional_access - : public logic_error + : public std::logic_error { public: -#if _LIBCPP_STD_VER > 11 - _LIBCPP_INLINE_VISIBILITY explicit bad_optional_access(const string& __arg) - : logic_error(__arg) {} - _LIBCPP_INLINE_VISIBILITY explicit bad_optional_access(const char* __arg) - : logic_error(__arg) {} - _LIBCPP_INLINE_VISIBILITY bad_optional_access(const bad_optional_access&) noexcept = default; - _LIBCPP_INLINE_VISIBILITY bad_optional_access& operator=(const bad_optional_access&) noexcept = default; -#else -private: - bad_optional_access(const bad_optional_access&); - bad_optional_access& operator=(const bad_optional_access&); -public: -#endif // _LIBCPP_STD_VER > 11 - // Get the key function ~bad_optional_access() into the dylib even if not compiling for C++1y + bad_optional_access() : std::logic_error("Bad optional Access") {} + +// Get the key function ~bad_optional_access() into the dylib virtual ~bad_optional_access() _NOEXCEPT; }; -}} // std::experimental +_LIBCPP_END_NAMESPACE_EXPERIMENTAL + #if _LIBCPP_STD_VER > 11 @@ -148,16 +164,14 @@ public: #include #include #include <__functional_base> - #include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -namespace std { namespace experimental { inline namespace __library_fundamentals_v1 { +_LIBCPP_BEGIN_NAMESPACE_LFTS struct in_place_t {}; constexpr in_place_t in_place{}; @@ -503,7 +517,7 @@ public: constexpr value_type const& value() const { if (!this->__engaged_) - throw bad_optional_access("optional::value: not engaged"); + throw bad_optional_access(); return this->__val_; } @@ -511,7 +525,7 @@ public: value_type& value() { if (!this->__engaged_) - throw bad_optional_access("optional::value: not engaged"); + throw bad_optional_access(); return this->__val_; } @@ -556,6 +570,7 @@ private: } }; +// Comparisons between optionals template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -569,6 +584,15 @@ operator==(const optional<_Tp>& __x, const optional<_Tp>& __y) return *__x == *__y; } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator!=(const optional<_Tp>& __x, const optional<_Tp>& __y) +{ + return !(__x == __y); +} + template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -579,9 +603,38 @@ operator<(const optional<_Tp>& __x, const optional<_Tp>& __y) return false; if (!static_cast(__x)) return true; - return less<_Tp>{}(*__x, *__y); + return *__x < *__y; } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>(const optional<_Tp>& __x, const optional<_Tp>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator<=(const optional<_Tp>& __x, const optional<_Tp>& __y) +{ + return !(__y < __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>=(const optional<_Tp>& __x, const optional<_Tp>& __y) +{ + return !(__x < __y); +} + + +// Comparisons with nullopt template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -600,6 +653,24 @@ operator==(nullopt_t, const optional<_Tp>& __x) noexcept return !static_cast(__x); } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator!=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast(__x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator!=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return static_cast(__x); +} + template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -618,6 +689,61 @@ operator<(nullopt_t, const optional<_Tp>& __x) noexcept return static_cast(__x); } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator<=(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return !static_cast(__x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator<=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>(const optional<_Tp>& __x, nullopt_t) noexcept +{ + return static_cast(__x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>=(const optional<_Tp>&, nullopt_t) noexcept +{ + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>=(nullopt_t, const optional<_Tp>& __x) noexcept +{ + return !static_cast(__x); +} + +// Comparisons with T template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -636,6 +762,24 @@ operator==(const _Tp& __v, const optional<_Tp>& __x) return static_cast(__x) ? *__x == __v : false; } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator!=(const optional<_Tp>& __x, const _Tp& __v) +{ + return static_cast(__x) ? !(*__x == __v) : true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator!=(const _Tp& __v, const optional<_Tp>& __x) +{ + return static_cast(__x) ? !(*__x == __v) : true; +} + template inline _LIBCPP_INLINE_VISIBILITY constexpr @@ -654,6 +798,61 @@ operator<(const _Tp& __v, const optional<_Tp>& __x) return static_cast(__x) ? less<_Tp>{}(__v, *__x) : false; } +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator<=(const optional<_Tp>& __x, const _Tp& __v) +{ + return !(__x > __v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator<=(const _Tp& __v, const optional<_Tp>& __x) +{ + return !(__v > __x); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>(const optional<_Tp>& __x, const _Tp& __v) +{ + return static_cast(__x) ? __v < __x : false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>(const _Tp& __v, const optional<_Tp>& __x) +{ + return static_cast(__x) ? __x < __v : true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>=(const optional<_Tp>& __x, const _Tp& __v) +{ + return !(__x < __v); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr +bool +operator>=(const _Tp& __v, const optional<_Tp>& __x) +{ + return !(__v < __x); +} + + template inline _LIBCPP_INLINE_VISIBILITY void @@ -671,7 +870,7 @@ make_optional(_Tp&& __v) return optional::type>(_VSTD::forward<_Tp>(__v)); } -}}} // namespace std::experimental::__library_fundamentals_v1 +_LIBCPP_END_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/optional.cpp b/src/optional.cpp index b614d8116..8c5dd76d8 100644 --- a/src/optional.cpp +++ b/src/optional.cpp @@ -9,8 +9,7 @@ #include "experimental/optional" -namespace std // purposefully not using versioning namespace -{ namespace experimental { +_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS @@ -22,4 +21,4 @@ bad_optional_access::~bad_optional_access() _NOEXCEPT = default; #endif -}} // std::experimental +_LIBCPP_END_NAMESPACE_EXPERIMENTAL diff --git a/test/utilities/optional/optional.bad_optional_access/char_pointer.pass.cpp b/test/utilities/optional/optional.bad_optional_access/char_pointer.pass.cpp deleted file mode 100644 index eacf34c34..000000000 --- a/test/utilities/optional/optional.bad_optional_access/char_pointer.pass.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class bad_optional_access; -// explicit bad_optional_access(const char* what_arg); - -#include -#include -#include -#include - -int main() -{ -#if _LIBCPP_STD_VER > 11 - using std::experimental::bad_optional_access; - - const char* s = "message"; - bad_optional_access e(s); - assert(std::strcmp(e.what(), s) == 0); -#endif // _LIBCPP_STD_VER > 11 -} diff --git a/test/utilities/optional/optional.bad_optional_access/copy_assign.pass.cpp b/test/utilities/optional/optional.bad_optional_access/copy_assign.pass.cpp deleted file mode 100644 index bb78ca4f4..000000000 --- a/test/utilities/optional/optional.bad_optional_access/copy_assign.pass.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class bad_optional_access; -// bad_optional_access& operator=(const bad_optional_access&); - -#include -#include -#include -#include -#include - -int main() -{ -#if _LIBCPP_STD_VER > 11 - using std::experimental::bad_optional_access; - - static_assert(std::is_nothrow_copy_assignable::value, ""); - const std::string s1("one message"); - const std::string s2("another message"); - bad_optional_access e1(s1); - bad_optional_access e2(s2); - assert(std::strcmp(e1.what(), e2.what()) != 0); - e1 = e2; - assert(std::strcmp(e1.what(), e2.what()) == 0); -#endif // _LIBCPP_STD_VER > 11 -} diff --git a/test/utilities/optional/optional.bad_optional_access/copy_ctor.pass.cpp b/test/utilities/optional/optional.bad_optional_access/copy_ctor.pass.cpp deleted file mode 100644 index 30ef533e7..000000000 --- a/test/utilities/optional/optional.bad_optional_access/copy_ctor.pass.cpp +++ /dev/null @@ -1,32 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class bad_optional_access; -// bad_optional_access(const bad_optional_access&); - -#include -#include -#include -#include -#include - -int main() -{ -#if _LIBCPP_STD_VER > 11 - using std::experimental::bad_optional_access; - - static_assert(std::is_nothrow_copy_constructible::value, ""); - const std::string s("another message"); - bad_optional_access e1(s); - bad_optional_access e2 = e1; - assert(std::strcmp(e1.what(), e2.what()) == 0); -#endif // _LIBCPP_STD_VER > 11 -} diff --git a/test/utilities/optional/optional.bad_optional_access/default.pass.cpp b/test/utilities/optional/optional.bad_optional_access/default.pass.cpp index 606be40b8..cecf98a35 100644 --- a/test/utilities/optional/optional.bad_optional_access/default.pass.cpp +++ b/test/utilities/optional/optional.bad_optional_access/default.pass.cpp @@ -9,7 +9,7 @@ // -// class bad_optional_access is not default constructible +// class bad_optional_access is default constructible #include #include @@ -18,7 +18,6 @@ int main() { #if _LIBCPP_STD_VER > 11 using std::experimental::bad_optional_access; - - static_assert(!std::is_default_constructible::value, ""); + bad_optional_access ex; #endif // _LIBCPP_STD_VER > 11 } diff --git a/test/utilities/optional/optional.bad_optional_access/string.pass.cpp b/test/utilities/optional/optional.bad_optional_access/string.pass.cpp deleted file mode 100644 index d0b3fb519..000000000 --- a/test/utilities/optional/optional.bad_optional_access/string.pass.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// class bad_optional_access; -// explicit bad_optional_access(const string& what_arg); - -#include -#include -#include -#include - -int main() -{ -#if _LIBCPP_STD_VER > 11 - using std::experimental::bad_optional_access; - - const std::string s("message"); - bad_optional_access e(s); - assert(std::strcmp(e.what(), s.c_str()) == 0); -#endif // _LIBCPP_STD_VER > 11 -} diff --git a/test/utilities/optional/optional.comp_with_t/equal.pass.cpp b/test/utilities/optional/optional.comp_with_t/equal.pass.cpp index 2380739cf..e796723cc 100644 --- a/test/utilities/optional/optional.comp_with_t/equal.pass.cpp +++ b/test/utilities/optional/optional.comp_with_t/equal.pass.cpp @@ -38,21 +38,21 @@ int main() typedef optional O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged constexpr O o3{val}; // engaged static_assert ( !(o1 == T(1)), "" ); - static_assert ( o2 == T(1), "" ); + static_assert ( (o2 == T(1)), "" ); static_assert ( !(o3 == T(1)), "" ); - static_assert ( o3 == T(2) , "" ); - static_assert ( o3 == val, "" ); + static_assert ( (o3 == T(2)), "" ); + static_assert ( (o3 == val), "" ); static_assert ( !(T(1) == o1), "" ); - static_assert ( T(1) == o2, "" ); + static_assert ( (T(1) == o2), "" ); static_assert ( !(T(1) == o3), "" ); - static_assert ( T(2) == o3 , "" ); - static_assert ( val == o3 , "" ); + static_assert ( (T(2) == o3), "" ); + static_assert ( (val == o3), "" ); } #endif } diff --git a/test/utilities/optional/optional.comp_with_t/greater.pass.cpp b/test/utilities/optional/optional.comp_with_t/greater.pass.cpp new file mode 100644 index 000000000..cf3923bb4 --- /dev/null +++ b/test/utilities/optional/optional.comp_with_t/greater.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator>(const optional& x, const T& v); +// template constexpr bool operator>(const T& v, const optional& x); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + + { + typedef X T; + typedef optional O; + + constexpr T val(2); + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert ( !(o1 > T(1)), "" ); + static_assert ( !(o2 > T(1)), "" ); // equal + static_assert ( (o3 > T(1)), "" ); + static_assert ( !(o2 > val), "" ); + static_assert ( !(o3 > val), "" ); // equal + static_assert ( !(o3 > T(3)), "" ); + + static_assert ( (T(1) > o1), "" ); + static_assert ( !(T(1) > o2), "" ); // equal + static_assert ( !(T(1) > o3), "" ); + static_assert ( (val > o2), "" ); + static_assert ( !(val > o3), "" ); // equal + static_assert ( (T(3) > o3), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp b/test/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp new file mode 100644 index 000000000..85fea1377 --- /dev/null +++ b/test/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator>=(const optional& x, const T& v); +// template constexpr bool operator>=(const T& v, const optional& x); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + + { + typedef X T; + typedef optional O; + + constexpr T val(2); + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert ( !(o1 >= T(1)), "" ); + static_assert ( (o2 >= T(1)), "" ); // equal + static_assert ( (o3 >= T(1)), "" ); + static_assert ( !(o2 >= val), "" ); + static_assert ( (o3 >= val), "" ); // equal + static_assert ( !(o3 >= T(3)), "" ); + + static_assert ( (T(1) >= o1), "" ); + static_assert ( (T(1) >= o2), "" ); // equal + static_assert ( !(T(1) >= o3), "" ); + static_assert ( (val >= o2), "" ); + static_assert ( (val >= o3), "" ); // equal + static_assert ( (T(3) >= o3), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.comp_with_t/less_equal.pass.cpp b/test/utilities/optional/optional.comp_with_t/less_equal.pass.cpp new file mode 100644 index 000000000..333f7cdea --- /dev/null +++ b/test/utilities/optional/optional.comp_with_t/less_equal.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator<=(const optional& x, const T& v); +// template constexpr bool operator<=(const T& v, const optional& x); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + + { + typedef X T; + typedef optional O; + + constexpr T val(2); + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert ( (o1 <= T(1)), "" ); + static_assert ( (o2 <= T(1)), "" ); // equal + static_assert ( !(o3 <= T(1)), "" ); + static_assert ( (o2 <= val), "" ); + static_assert ( (o3 <= val), "" ); // equal + static_assert ( (o3 <= T(3)), "" ); + + static_assert ( !(T(1) <= o1), "" ); + static_assert ( (T(1) <= o2), "" ); // equal + static_assert ( (T(1) <= o3), "" ); + static_assert ( !(val <= o2), "" ); + static_assert ( (val <= o3), "" ); // equal + static_assert ( !(T(3) <= o3), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp b/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp index 808537608..e35df21bb 100644 --- a/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp +++ b/test/utilities/optional/optional.comp_with_t/less_than.pass.cpp @@ -37,24 +37,24 @@ int main() { typedef X T; typedef optional O; - + constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged constexpr O o3{val}; // engaged - static_assert ( o1 < T(1) , "" ); - static_assert ( !(o2 < T(1)), "" ); + static_assert ( (o1 < T(1)), "" ); + static_assert ( !(o2 < T(1)), "" ); // equal static_assert ( !(o3 < T(1)), "" ); - static_assert ( o2 < T(2) , "" ); - static_assert ( o2 < T(val), "" ); - static_assert ( o3 < T(3) , "" ); + static_assert ( (o2 < val), "" ); + static_assert ( !(o3 < val), "" ); // equal + static_assert ( (o3 < T(3)), "" ); static_assert ( !(T(1) < o1), "" ); - static_assert ( !(T(1) < o2), "" ); - static_assert ( T(1) < o3 , "" ); - static_assert ( !(T(2) < o2), "" ); - static_assert (!(T(val) < o2), "" ); + static_assert ( !(T(1) < o2), "" ); // equal + static_assert ( (T(1) < o3), "" ); + static_assert ( !(val < o2), "" ); + static_assert ( !(val < o3), "" ); // equal static_assert ( !(T(3) < o3), "" ); } #endif diff --git a/test/utilities/optional/optional.comp_with_t/not_equal.pass.cpp b/test/utilities/optional/optional.comp_with_t/not_equal.pass.cpp new file mode 100644 index 000000000..0dad68d38 --- /dev/null +++ b/test/utilities/optional/optional.comp_with_t/not_equal.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator!=(const optional& x, const T& v); +// template constexpr bool operator!=(const T& v, const optional& x); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator == ( const X &lhs, const X &rhs ) + { return lhs.i_ == rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef X T; + typedef optional O; + + constexpr T val(2); + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert ( (o1 != T(1)), "" ); + static_assert ( !(o2 != T(1)), "" ); + static_assert ( (o3 != T(1)), "" ); + static_assert ( !(o3 != T(2)), "" ); + static_assert ( !(o3 != val), "" ); + + static_assert ( (T(1) != o1), "" ); + static_assert ( !(T(1) != o2), "" ); + static_assert ( (T(1) != o3), "" ); + static_assert ( !(T(2) != o3), "" ); + static_assert ( !(val != o3), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.nullops/eqaul.pass.cpp b/test/utilities/optional/optional.nullops/equal.pass.cpp similarity index 92% rename from test/utilities/optional/optional.nullops/eqaul.pass.cpp rename to test/utilities/optional/optional.nullops/equal.pass.cpp index 54fb522d8..931db6144 100644 --- a/test/utilities/optional/optional.nullops/eqaul.pass.cpp +++ b/test/utilities/optional/optional.nullops/equal.pass.cpp @@ -29,9 +29,9 @@ int main() constexpr O o1; // disengaged constexpr O o2{1}; // engaged - static_assert ( nullopt == o1 , "" ); + static_assert ( (nullopt == o1), "" ); static_assert ( !(nullopt == o2), "" ); - static_assert ( o1 == nullopt , "" ); + static_assert ( (o1 == nullopt), "" ); static_assert ( !(o2 == nullopt), "" ); static_assert (noexcept(nullopt == o1), ""); diff --git a/test/utilities/optional/optional.nullops/greater.pass.cpp b/test/utilities/optional/optional.nullops/greater.pass.cpp new file mode 100644 index 000000000..b72a4d3f1 --- /dev/null +++ b/test/utilities/optional/optional.nullops/greater.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +// + +// template constexpr bool operator>(const optional& x, nullopt_t) noexcept; +// template constexpr bool operator>(nullopt_t, const optional& x) noexcept; + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::experimental::optional; + using std::experimental::nullopt_t; + using std::experimental::nullopt; + + { + typedef int T; + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + + static_assert ( !(nullopt > o1), "" ); + static_assert ( !(nullopt > o2), "" ); + static_assert ( !(o1 > nullopt), "" ); + static_assert ( (o2 > nullopt), "" ); + + static_assert (noexcept(nullopt > o1), ""); + static_assert (noexcept(o1 > nullopt), ""); + } +#endif +} diff --git a/test/utilities/optional/optional.nullops/greater_equal.pass.cpp b/test/utilities/optional/optional.nullops/greater_equal.pass.cpp new file mode 100644 index 000000000..86c8743b5 --- /dev/null +++ b/test/utilities/optional/optional.nullops/greater_equal.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +// + +// template constexpr bool operator>=(const optional& x, nullopt_t) noexcept; +// template constexpr bool operator>=(nullopt_t, const optional& x) noexcept; + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::experimental::optional; + using std::experimental::nullopt_t; + using std::experimental::nullopt; + + { + typedef int T; + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + + static_assert ( (nullopt >= o1), "" ); + static_assert ( !(nullopt >= o2), "" ); + static_assert ( (o1 >= nullopt), "" ); + static_assert ( (o2 >= nullopt), "" ); + + static_assert (noexcept(nullopt >= o1), ""); + static_assert (noexcept(o1 >= nullopt), ""); + } +#endif +} diff --git a/test/utilities/optional/optional.nullops/less_equal.pass.cpp b/test/utilities/optional/optional.nullops/less_equal.pass.cpp new file mode 100644 index 000000000..3e8444bc7 --- /dev/null +++ b/test/utilities/optional/optional.nullops/less_equal.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +// + +// template constexpr bool operator<=(const optional& x, nullopt_t) noexcept; +// template constexpr bool operator<=(nullopt_t, const optional& x) noexcept; + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::experimental::optional; + using std::experimental::nullopt_t; + using std::experimental::nullopt; + + { + typedef int T; + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + + static_assert ( (nullopt <= o1), "" ); + static_assert ( (nullopt <= o2), "" ); + static_assert ( (o1 <= nullopt), "" ); + static_assert ( !(o2 <= nullopt), "" ); + + static_assert (noexcept(nullopt <= o1), ""); + static_assert (noexcept(o1 <= nullopt), ""); + } +#endif +} diff --git a/test/utilities/optional/optional.nullops/less_than.pass.cpp b/test/utilities/optional/optional.nullops/less_than.pass.cpp index 576a98aa4..149c809b0 100644 --- a/test/utilities/optional/optional.nullops/less_than.pass.cpp +++ b/test/utilities/optional/optional.nullops/less_than.pass.cpp @@ -30,7 +30,7 @@ int main() constexpr O o2{1}; // engaged static_assert ( !(nullopt < o1), "" ); - static_assert ( nullopt < o2 , "" ); + static_assert ( (nullopt < o2), "" ); static_assert ( !(o1 < nullopt), "" ); static_assert ( !(o2 < nullopt), "" ); diff --git a/test/utilities/optional/optional.nullops/not_equal.pass.cpp b/test/utilities/optional/optional.nullops/not_equal.pass.cpp new file mode 100644 index 000000000..6f28edf6d --- /dev/null +++ b/test/utilities/optional/optional.nullops/not_equal.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + + +// + +// template constexpr bool operator!=(const optional& x, nullopt_t) noexcept; +// template constexpr bool operator!=(nullopt_t, const optional& x) noexcept; + +#include + +int main() +{ +#if _LIBCPP_STD_VER > 11 + using std::experimental::optional; + using std::experimental::nullopt_t; + using std::experimental::nullopt; + + { + typedef int T; + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + + static_assert ( !(nullopt != o1), "" ); + static_assert ( (nullopt != o2), "" ); + static_assert ( !(o1 != nullopt), "" ); + static_assert ( (o2 != nullopt), "" ); + + static_assert (noexcept(nullopt != o1), ""); + static_assert (noexcept(o1 != nullopt), ""); + } +#endif +} diff --git a/test/utilities/optional/optional.relops/greater_equal.pass.cpp b/test/utilities/optional/optional.relops/greater_equal.pass.cpp new file mode 100644 index 000000000..98d6855f9 --- /dev/null +++ b/test/utilities/optional/optional.relops/greater_equal.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator>= (const optional& x, const optional& y); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged + + static_assert ( (o1 >= o1), "" ); + static_assert ( (o1 >= o2), "" ); + static_assert ( !(o1 >= o3), "" ); + static_assert ( !(o1 >= o4), "" ); + static_assert ( !(o1 >= o5), "" ); + + static_assert ( (o2 >= o1), "" ); + static_assert ( (o2 >= o2), "" ); + static_assert ( !(o2 >= o3), "" ); + static_assert ( !(o2 >= o4), "" ); + static_assert ( !(o2 >= o5), "" ); + + static_assert ( (o3 >= o1), "" ); + static_assert ( (o3 >= o2), "" ); + static_assert ( (o3 >= o3), "" ); + static_assert ( !(o3 >= o4), "" ); + static_assert ( (o3 >= o5), "" ); + + static_assert ( (o4 >= o1), "" ); + static_assert ( (o4 >= o2), "" ); + static_assert ( (o4 >= o3), "" ); + static_assert ( (o4 >= o4), "" ); + static_assert ( (o4 >= o5), "" ); + + static_assert ( (o5 >= o1), "" ); + static_assert ( (o5 >= o2), "" ); + static_assert ( (o5 >= o3), "" ); + static_assert ( !(o5 >= o4), "" ); + static_assert ( (o5 >= o5), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.relops/greater_than.pass.cpp b/test/utilities/optional/optional.relops/greater_than.pass.cpp new file mode 100644 index 000000000..d51bd4f2a --- /dev/null +++ b/test/utilities/optional/optional.relops/greater_than.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator> (const optional& x, const optional& y); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged + + static_assert ( !(o1 > o1), "" ); + static_assert ( !(o1 > o2), "" ); + static_assert ( !(o1 > o3), "" ); + static_assert ( !(o1 > o4), "" ); + static_assert ( !(o1 > o5), "" ); + + static_assert ( !(o2 > o1), "" ); + static_assert ( !(o2 > o2), "" ); + static_assert ( !(o2 > o3), "" ); + static_assert ( !(o2 > o4), "" ); + static_assert ( !(o2 > o5), "" ); + + static_assert ( (o3 > o1), "" ); + static_assert ( (o3 > o2), "" ); + static_assert ( !(o3 > o3), "" ); + static_assert ( !(o3 > o4), "" ); + static_assert ( !(o3 > o5), "" ); + + static_assert ( (o4 > o1), "" ); + static_assert ( (o4 > o2), "" ); + static_assert ( (o4 > o3), "" ); + static_assert ( !(o4 > o4), "" ); + static_assert ( (o4 > o5), "" ); + + static_assert ( (o5 > o1), "" ); + static_assert ( (o5 > o2), "" ); + static_assert ( !(o5 > o3), "" ); + static_assert ( !(o5 > o4), "" ); + static_assert ( !(o5 > o5), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.relops/less_equal.pass.cpp b/test/utilities/optional/optional.relops/less_equal.pass.cpp new file mode 100644 index 000000000..326f3a896 --- /dev/null +++ b/test/utilities/optional/optional.relops/less_equal.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator<= (const optional& x, const optional& y); + +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator < ( const X &lhs, const X &rhs ) + { return lhs.i_ < rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged + + static_assert ( (o1 <= o1), "" ); + static_assert ( (o1 <= o2), "" ); + static_assert ( (o1 <= o3), "" ); + static_assert ( (o1 <= o4), "" ); + static_assert ( (o1 <= o5), "" ); + + static_assert ( (o2 <= o1), "" ); + static_assert ( (o2 <= o2), "" ); + static_assert ( (o2 <= o3), "" ); + static_assert ( (o2 <= o4), "" ); + static_assert ( (o2 <= o5), "" ); + + static_assert ( !(o3 <= o1), "" ); + static_assert ( !(o3 <= o2), "" ); + static_assert ( (o3 <= o3), "" ); + static_assert ( (o3 <= o4), "" ); + static_assert ( (o3 <= o5), "" ); + + static_assert ( !(o4 <= o1), "" ); + static_assert ( !(o4 <= o2), "" ); + static_assert ( !(o4 <= o3), "" ); + static_assert ( (o4 <= o4), "" ); + static_assert ( !(o4 <= o5), "" ); + + static_assert ( !(o5 <= o1), "" ); + static_assert ( !(o5 <= o2), "" ); + static_assert ( (o5 <= o3), "" ); + static_assert ( (o5 <= o4), "" ); + static_assert ( (o5 <= o5), "" ); + } +#endif +} diff --git a/test/utilities/optional/optional.relops/less_than.pass.cpp b/test/utilities/optional/optional.relops/less_than.pass.cpp index 8d70e92dd..37f7e1942 100644 --- a/test/utilities/optional/optional.relops/less_than.pass.cpp +++ b/test/utilities/optional/optional.relops/less_than.pass.cpp @@ -43,20 +43,20 @@ int main() static_assert ( !(o1 < o1), "" ); static_assert ( !(o1 < o2), "" ); - static_assert ( o1 < o3 , "" ); - static_assert ( o1 < o4 , "" ); - static_assert ( o1 < o5 , "" ); + static_assert ( (o1 < o3), "" ); + static_assert ( (o1 < o4), "" ); + static_assert ( (o1 < o5), "" ); static_assert ( !(o2 < o1), "" ); static_assert ( !(o2 < o2), "" ); - static_assert ( o2 < o3 , "" ); - static_assert ( o2 < o4 , "" ); - static_assert ( o2 < o5 , "" ); + static_assert ( (o2 < o3), "" ); + static_assert ( (o2 < o4), "" ); + static_assert ( (o2 < o5), "" ); static_assert ( !(o3 < o1), "" ); static_assert ( !(o3 < o2), "" ); static_assert ( !(o3 < o3), "" ); - static_assert ( o3 < o4 , "" ); + static_assert ( (o3 < o4), "" ); static_assert ( !(o3 < o5), "" ); static_assert ( !(o4 < o1), "" ); @@ -68,7 +68,7 @@ int main() static_assert ( !(o5 < o1), "" ); static_assert ( !(o5 < o2), "" ); static_assert ( !(o5 < o3), "" ); - static_assert ( o5 < o4 , "" ); + static_assert ( (o5 < o4), "" ); static_assert ( !(o5 < o5), "" ); } #endif diff --git a/test/utilities/optional/optional.relops/not_equal.pass.cpp b/test/utilities/optional/optional.relops/not_equal.pass.cpp new file mode 100644 index 000000000..f386c7e36 --- /dev/null +++ b/test/utilities/optional/optional.relops/not_equal.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr bool operator!=(const optional& x, const optional& y); + +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + int i_; + + constexpr X(int i) : i_(i) {} +}; + +constexpr bool operator == ( const X &lhs, const X &rhs ) + { return lhs.i_ == rhs.i_ ; } + +#endif + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef X T; + typedef optional O; + + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged + + static_assert ( !(o1 != o1), "" ); + static_assert ( !(o1 != o2), "" ); + static_assert ( (o1 != o3), "" ); + static_assert ( (o1 != o4), "" ); + static_assert ( (o1 != o5), "" ); + + static_assert ( !(o2 != o1), "" ); + static_assert ( !(o2 != o2), "" ); + static_assert ( (o2 != o3), "" ); + static_assert ( (o2 != o4), "" ); + static_assert ( (o2 != o5), "" ); + + static_assert ( (o3 != o1), "" ); + static_assert ( (o3 != o2), "" ); + static_assert ( !(o3 != o3), "" ); + static_assert ( (o3 != o4), "" ); + static_assert ( !(o3 != o5), "" ); + + static_assert ( (o4 != o1), "" ); + static_assert ( (o4 != o2), "" ); + static_assert ( (o4 != o3), "" ); + static_assert ( !(o4 != o4), "" ); + static_assert ( (o4 != o5), "" ); + + static_assert ( (o5 != o1), "" ); + static_assert ( (o5 != o2), "" ); + static_assert ( !(o5 != o3), "" ); + static_assert ( (o5 != o4), "" ); + static_assert ( !(o5 != o5), "" ); + + } +#endif +}