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
This commit is contained in:
parent
fff544efbd
commit
4ad67e08cb
@ -16,131 +16,147 @@
|
|||||||
|
|
||||||
// C++1y
|
// C++1y
|
||||||
|
|
||||||
#include <initializer_list>
|
namespace std { namespace experimental { inline namespace fundamentals_v1 {
|
||||||
|
|
||||||
namespace std { namespace experimental {
|
// 5.3, optional for object types
|
||||||
|
template <class T> class optional;
|
||||||
|
|
||||||
// optional for object types
|
// 5.4, In-place construction
|
||||||
template <class T>
|
struct in_place_t{};
|
||||||
class optional
|
constexpr in_place_t in_place{};
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef T value_type;
|
|
||||||
|
|
||||||
// constructors
|
// 5.5, No-value state indicator
|
||||||
constexpr optional() noexcept;
|
struct nullopt_t{see below};
|
||||||
constexpr optional(nullopt_t) noexcept;
|
constexpr nullopt_t nullopt(unspecified);
|
||||||
optional(const optional&);
|
|
||||||
optional(optional&&) noexcept(is_nothrow_move_constructible<T>::value);
|
|
||||||
constexpr optional(const T&);
|
|
||||||
constexpr optional(T&&);
|
|
||||||
template <class... Args> constexpr explicit optional(in_place_t, Args&&...);
|
|
||||||
template <class U, class... Args>
|
|
||||||
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
|
||||||
|
|
||||||
// destructor
|
// 5.6, Class bad_optional_access
|
||||||
~optional();
|
class bad_optional_access;
|
||||||
|
|
||||||
// assignment
|
// 5.7, Relational operators
|
||||||
optional& operator=(nullopt_t) noexcept;
|
template <class T>
|
||||||
optional& operator=(const optional&);
|
constexpr bool operator==(const optional<T>&, const optional<T>&);
|
||||||
optional& operator=(optional&&)
|
template <class T>
|
||||||
noexcept(is_nothrow_move_assignable<T>::value &&
|
constexpr bool operator!=(const optional<T>&, const optional<T>&);
|
||||||
is_nothrow_move_constructible<T>::value);
|
template <class T>
|
||||||
template <class U> optional& operator=(U&&);
|
constexpr bool operator<(const optional<T>&, const optional<T>&);
|
||||||
template <class... Args> void emplace(Args&&...);
|
template <class T>
|
||||||
template <class U, class... Args> void emplace(initializer_list<U>, Args&&...);
|
constexpr bool operator>(const optional<T>&, const optional<T>&);
|
||||||
|
template <class T>
|
||||||
|
constexpr bool operator<=(const optional<T>&, const optional<T>&);
|
||||||
|
template <class T>
|
||||||
|
constexpr bool operator>=(const optional<T>&, const optional<T>&);
|
||||||
|
|
||||||
// swap
|
// 5.8, Comparison with nullopt
|
||||||
void swap(optional&)
|
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
|
||||||
noexcept(is_nothrow_move_constructible<T>::value &&
|
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
|
||||||
noexcept(swap(declval<T&>(), declval<T&>())));
|
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
|
||||||
|
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
|
||||||
|
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
|
||||||
|
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
|
||||||
|
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
|
||||||
|
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
|
||||||
|
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
|
||||||
|
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
|
||||||
|
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
|
||||||
|
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
|
||||||
|
|
||||||
// observers
|
// 5.9, Comparison with T
|
||||||
constexpr T const* operator->() const;
|
template <class T> constexpr bool operator==(const optional<T>&, const T&);
|
||||||
T* operator->();
|
template <class T> constexpr bool operator==(const T&, const optional<T>&);
|
||||||
constexpr T const& operator*() const;
|
template <class T> constexpr bool operator!=(const optional<T>&, const T&);
|
||||||
T& operator*();
|
template <class T> constexpr bool operator!=(const T&, const optional<T>&);
|
||||||
constexpr explicit operator bool() const noexcept;
|
template <class T> constexpr bool operator<(const optional<T>&, const T&);
|
||||||
constexpr T const& value() const;
|
template <class T> constexpr bool operator<(const T&, const optional<T>&);
|
||||||
T& value();
|
template <class T> constexpr bool operator<=(const optional<T>&, const T&);
|
||||||
template <class U> constexpr T value_or(U&&) const&;
|
template <class T> constexpr bool operator<=(const T&, const optional<T>&);
|
||||||
template <class U> T value_or(U&&) &&;
|
template <class T> constexpr bool operator>(const optional<T>&, const T&);
|
||||||
};
|
template <class T> constexpr bool operator>(const T&, const optional<T>&);
|
||||||
|
template <class T> constexpr bool operator>=(const optional<T>&, const T&);
|
||||||
|
template <class T> constexpr bool operator>=(const T&, const optional<T>&);
|
||||||
|
|
||||||
// In-place construction
|
// 5.10, Specialized algorithms
|
||||||
struct in_place_t{};
|
template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below);
|
||||||
constexpr in_place_t in_place{};
|
template <class T> constexpr optional<see below> make_optional(T&&);
|
||||||
|
|
||||||
// Disengaged state indicator
|
template <class T>
|
||||||
struct nullopt_t{see below};
|
class optional
|
||||||
constexpr nullopt_t nullopt(unspecified);
|
{
|
||||||
|
public:
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
// class bad_optional_access
|
// 5.3.1, Constructors
|
||||||
class bad_optional_access
|
constexpr optional() noexcept;
|
||||||
: public logic_error
|
constexpr optional(nullopt_t) noexcept;
|
||||||
{
|
optional(const optional&);
|
||||||
public:
|
optional(optional&&) noexcept(see below);
|
||||||
explicit bad_optional_access(const string& what_arg);
|
constexpr optional(const T&);
|
||||||
explicit bad_optional_access(const char* what_arg);
|
constexpr optional(T&&);
|
||||||
};
|
template <class... Args> constexpr explicit optional(in_place_t, Args&&...);
|
||||||
|
template <class U, class... Args>
|
||||||
|
constexpr explicit optional(in_place_t, initializer_list<U>, Args&&...);
|
||||||
|
|
||||||
// Relational operators
|
// 5.3.2, Destructor
|
||||||
template <class T> constexpr bool operator==(const optional<T>&, const optional<T>&);
|
~optional();
|
||||||
template <class T> constexpr bool operator< (const optional<T>&, const optional<T>&);
|
|
||||||
|
|
||||||
// Comparison with nullopt
|
// 5.3.3, Assignment
|
||||||
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
|
optional& operator=(nullopt_t) noexcept;
|
||||||
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
|
optional& operator=(const optional&);
|
||||||
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
|
optional& operator=(optional&&) noexcept(see below);
|
||||||
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
|
template <class U> optional& operator=(U&&);
|
||||||
|
template <class... Args> void emplace(Args&&...);
|
||||||
|
template <class U, class... Args>
|
||||||
|
void emplace(initializer_list<U>, Args&&...);
|
||||||
|
|
||||||
// Comparison with T
|
// 5.3.4, Swap
|
||||||
template <class T> constexpr bool operator==(const optional<T>&, const T&);
|
void swap(optional&) noexcept(see below);
|
||||||
template <class T> constexpr bool operator==(const T&, const optional<T>&);
|
|
||||||
template <class T> constexpr bool operator<(const optional<T>&, const T&);
|
|
||||||
template <class T> constexpr bool operator<(const T&, const optional<T>&);
|
|
||||||
|
|
||||||
// Specialized algorithms
|
// 5.3.5, Observers
|
||||||
template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below);
|
constexpr T const* operator ->() const;
|
||||||
template <class T> constexpr optional<typename decay<T>::type> make_optional(T&&);
|
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 <class U> constexpr T value_or(U&&) const &;
|
||||||
|
template <class U> constexpr T value_or(U&&) &&;
|
||||||
|
|
||||||
// hash support
|
private:
|
||||||
template <class T> struct hash;
|
T* val; // exposition only
|
||||||
template <class T> struct hash<optional<T>>;
|
};
|
||||||
|
|
||||||
}} // std::experimental
|
} // namespace fundamentals_v1
|
||||||
|
} // namespace experimental
|
||||||
|
|
||||||
|
// 5.11, Hash support
|
||||||
|
template <class T> struct hash;
|
||||||
|
template <class T> struct hash<experimental::optional<T>>;
|
||||||
|
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <__config>
|
#include <experimental/__config>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace std { namespace experimental {
|
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||||
|
|
||||||
class _LIBCPP_EXCEPTION_ABI bad_optional_access
|
class _LIBCPP_EXCEPTION_ABI bad_optional_access
|
||||||
: public logic_error
|
: public std::logic_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#if _LIBCPP_STD_VER > 11
|
bad_optional_access() : std::logic_error("Bad optional Access") {}
|
||||||
_LIBCPP_INLINE_VISIBILITY explicit bad_optional_access(const string& __arg)
|
|
||||||
: logic_error(__arg) {}
|
// Get the key function ~bad_optional_access() into the dylib
|
||||||
_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
|
|
||||||
virtual ~bad_optional_access() _NOEXCEPT;
|
virtual ~bad_optional_access() _NOEXCEPT;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // std::experimental
|
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||||
|
|
||||||
|
|
||||||
#if _LIBCPP_STD_VER > 11
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
|
||||||
@ -148,16 +164,14 @@ public:
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <__functional_base>
|
#include <__functional_base>
|
||||||
|
|
||||||
#include <__undef_min_max>
|
#include <__undef_min_max>
|
||||||
|
|
||||||
#include <__debug>
|
#include <__debug>
|
||||||
|
|
||||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace std { namespace experimental { inline namespace __library_fundamentals_v1 {
|
_LIBCPP_BEGIN_NAMESPACE_LFTS
|
||||||
|
|
||||||
struct in_place_t {};
|
struct in_place_t {};
|
||||||
constexpr in_place_t in_place{};
|
constexpr in_place_t in_place{};
|
||||||
@ -503,7 +517,7 @@ public:
|
|||||||
constexpr value_type const& value() const
|
constexpr value_type const& value() const
|
||||||
{
|
{
|
||||||
if (!this->__engaged_)
|
if (!this->__engaged_)
|
||||||
throw bad_optional_access("optional<T>::value: not engaged");
|
throw bad_optional_access();
|
||||||
return this->__val_;
|
return this->__val_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,7 +525,7 @@ public:
|
|||||||
value_type& value()
|
value_type& value()
|
||||||
{
|
{
|
||||||
if (!this->__engaged_)
|
if (!this->__engaged_)
|
||||||
throw bad_optional_access("optional<T>::value: not engaged");
|
throw bad_optional_access();
|
||||||
return this->__val_;
|
return this->__val_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,6 +570,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Comparisons between optionals
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -569,6 +584,15 @@ operator==(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
|||||||
return *__x == *__y;
|
return *__x == *__y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator!=(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
||||||
|
{
|
||||||
|
return !(__x == __y);
|
||||||
|
}
|
||||||
|
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -579,9 +603,38 @@ operator<(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
|||||||
return false;
|
return false;
|
||||||
if (!static_cast<bool>(__x))
|
if (!static_cast<bool>(__x))
|
||||||
return true;
|
return true;
|
||||||
return less<_Tp>{}(*__x, *__y);
|
return *__x < *__y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
||||||
|
{
|
||||||
|
return __y < __x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator<=(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
||||||
|
{
|
||||||
|
return !(__y < __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>=(const optional<_Tp>& __x, const optional<_Tp>& __y)
|
||||||
|
{
|
||||||
|
return !(__x < __y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Comparisons with nullopt
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -600,6 +653,24 @@ operator==(nullopt_t, const optional<_Tp>& __x) noexcept
|
|||||||
return !static_cast<bool>(__x);
|
return !static_cast<bool>(__x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator!=(const optional<_Tp>& __x, nullopt_t) noexcept
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator!=(nullopt_t, const optional<_Tp>& __x) noexcept
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x);
|
||||||
|
}
|
||||||
|
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -618,6 +689,61 @@ operator<(nullopt_t, const optional<_Tp>& __x) noexcept
|
|||||||
return static_cast<bool>(__x);
|
return static_cast<bool>(__x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator<=(const optional<_Tp>& __x, nullopt_t) noexcept
|
||||||
|
{
|
||||||
|
return !static_cast<bool>(__x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator<=(nullopt_t, const optional<_Tp>& __x) noexcept
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>(const optional<_Tp>& __x, nullopt_t) noexcept
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>(nullopt_t, const optional<_Tp>& __x) noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>=(const optional<_Tp>&, nullopt_t) noexcept
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>=(nullopt_t, const optional<_Tp>& __x) noexcept
|
||||||
|
{
|
||||||
|
return !static_cast<bool>(__x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comparisons with T
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -636,6 +762,24 @@ operator==(const _Tp& __v, const optional<_Tp>& __x)
|
|||||||
return static_cast<bool>(__x) ? *__x == __v : false;
|
return static_cast<bool>(__x) ? *__x == __v : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator!=(const optional<_Tp>& __x, const _Tp& __v)
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x) ? !(*__x == __v) : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator!=(const _Tp& __v, const optional<_Tp>& __x)
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x) ? !(*__x == __v) : true;
|
||||||
|
}
|
||||||
|
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
constexpr
|
constexpr
|
||||||
@ -654,6 +798,61 @@ operator<(const _Tp& __v, const optional<_Tp>& __x)
|
|||||||
return static_cast<bool>(__x) ? less<_Tp>{}(__v, *__x) : false;
|
return static_cast<bool>(__x) ? less<_Tp>{}(__v, *__x) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator<=(const optional<_Tp>& __x, const _Tp& __v)
|
||||||
|
{
|
||||||
|
return !(__x > __v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator<=(const _Tp& __v, const optional<_Tp>& __x)
|
||||||
|
{
|
||||||
|
return !(__v > __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>(const optional<_Tp>& __x, const _Tp& __v)
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x) ? __v < __x : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>(const _Tp& __v, const optional<_Tp>& __x)
|
||||||
|
{
|
||||||
|
return static_cast<bool>(__x) ? __x < __v : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>=(const optional<_Tp>& __x, const _Tp& __v)
|
||||||
|
{
|
||||||
|
return !(__x < __v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class _Tp>
|
||||||
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
constexpr
|
||||||
|
bool
|
||||||
|
operator>=(const _Tp& __v, const optional<_Tp>& __x)
|
||||||
|
{
|
||||||
|
return !(__v < __x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class _Tp>
|
template <class _Tp>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
void
|
void
|
||||||
@ -671,7 +870,7 @@ make_optional(_Tp&& __v)
|
|||||||
return optional<typename decay<_Tp>::type>(_VSTD::forward<_Tp>(__v));
|
return optional<typename decay<_Tp>::type>(_VSTD::forward<_Tp>(__v));
|
||||||
}
|
}
|
||||||
|
|
||||||
}}} // namespace std::experimental::__library_fundamentals_v1
|
_LIBCPP_END_NAMESPACE_LFTS
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
|
|
||||||
#include "experimental/optional"
|
#include "experimental/optional"
|
||||||
|
|
||||||
namespace std // purposefully not using versioning namespace
|
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
|
||||||
{ namespace experimental {
|
|
||||||
|
|
||||||
#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
|
#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
|
||||||
|
|
||||||
@ -22,4 +21,4 @@ bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}} // std::experimental
|
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
|
||||||
|
@ -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.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// <optional>
|
|
||||||
|
|
||||||
// class bad_optional_access;
|
|
||||||
// explicit bad_optional_access(const char* what_arg);
|
|
||||||
|
|
||||||
#include <experimental/optional>
|
|
||||||
#include <string>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
@ -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.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// <optional>
|
|
||||||
|
|
||||||
// class bad_optional_access;
|
|
||||||
// bad_optional_access& operator=(const bad_optional_access&);
|
|
||||||
|
|
||||||
#include <experimental/optional>
|
|
||||||
#include <string>
|
|
||||||
#include <cstring>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
#if _LIBCPP_STD_VER > 11
|
|
||||||
using std::experimental::bad_optional_access;
|
|
||||||
|
|
||||||
static_assert(std::is_nothrow_copy_assignable<bad_optional_access>::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
|
|
||||||
}
|
|
@ -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.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// <optional>
|
|
||||||
|
|
||||||
// class bad_optional_access;
|
|
||||||
// bad_optional_access(const bad_optional_access&);
|
|
||||||
|
|
||||||
#include <experimental/optional>
|
|
||||||
#include <string>
|
|
||||||
#include <cstring>
|
|
||||||
#include <type_traits>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
#if _LIBCPP_STD_VER > 11
|
|
||||||
using std::experimental::bad_optional_access;
|
|
||||||
|
|
||||||
static_assert(std::is_nothrow_copy_constructible<bad_optional_access>::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
|
|
||||||
}
|
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// <optional>
|
// <optional>
|
||||||
|
|
||||||
// class bad_optional_access is not default constructible
|
// class bad_optional_access is default constructible
|
||||||
|
|
||||||
#include <experimental/optional>
|
#include <experimental/optional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -18,7 +18,6 @@ int main()
|
|||||||
{
|
{
|
||||||
#if _LIBCPP_STD_VER > 11
|
#if _LIBCPP_STD_VER > 11
|
||||||
using std::experimental::bad_optional_access;
|
using std::experimental::bad_optional_access;
|
||||||
|
bad_optional_access ex;
|
||||||
static_assert(!std::is_default_constructible<bad_optional_access>::value, "");
|
|
||||||
#endif // _LIBCPP_STD_VER > 11
|
#endif // _LIBCPP_STD_VER > 11
|
||||||
}
|
}
|
||||||
|
@ -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.
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// <optional>
|
|
||||||
|
|
||||||
// class bad_optional_access;
|
|
||||||
// explicit bad_optional_access(const string& what_arg);
|
|
||||||
|
|
||||||
#include <experimental/optional>
|
|
||||||
#include <string>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
@ -38,21 +38,21 @@ int main()
|
|||||||
typedef optional<T> O;
|
typedef optional<T> O;
|
||||||
|
|
||||||
constexpr T val(2);
|
constexpr T val(2);
|
||||||
constexpr O o1; // disengaged
|
constexpr O o1; // disengaged
|
||||||
constexpr O o2{1}; // engaged
|
constexpr O o2{1}; // engaged
|
||||||
constexpr O o3{val}; // engaged
|
constexpr O o3{val}; // engaged
|
||||||
|
|
||||||
static_assert ( !(o1 == T(1)), "" );
|
static_assert ( !(o1 == T(1)), "" );
|
||||||
static_assert ( o2 == T(1), "" );
|
static_assert ( (o2 == T(1)), "" );
|
||||||
static_assert ( !(o3 == T(1)), "" );
|
static_assert ( !(o3 == T(1)), "" );
|
||||||
static_assert ( o3 == T(2) , "" );
|
static_assert ( (o3 == T(2)), "" );
|
||||||
static_assert ( o3 == val, "" );
|
static_assert ( (o3 == val), "" );
|
||||||
|
|
||||||
static_assert ( !(T(1) == o1), "" );
|
static_assert ( !(T(1) == o1), "" );
|
||||||
static_assert ( T(1) == o2, "" );
|
static_assert ( (T(1) == o2), "" );
|
||||||
static_assert ( !(T(1) == o3), "" );
|
static_assert ( !(T(1) == o3), "" );
|
||||||
static_assert ( T(2) == o3 , "" );
|
static_assert ( (T(2) == o3), "" );
|
||||||
static_assert ( val == o3 , "" );
|
static_assert ( (val == o3), "" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator>(const optional<T>& x, const T& v);
|
||||||
|
// template <class T> constexpr bool operator>(const T& v, const optional<T>& x);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<T> 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
|
||||||
|
}
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator>=(const optional<T>& x, const T& v);
|
||||||
|
// template <class T> constexpr bool operator>=(const T& v, const optional<T>& x);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<T> 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
|
||||||
|
}
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator<=(const optional<T>& x, const T& v);
|
||||||
|
// template <class T> constexpr bool operator<=(const T& v, const optional<T>& x);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<T> 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
|
||||||
|
}
|
@ -37,24 +37,24 @@ int main()
|
|||||||
{
|
{
|
||||||
typedef X T;
|
typedef X T;
|
||||||
typedef optional<T> O;
|
typedef optional<T> O;
|
||||||
|
|
||||||
constexpr T val(2);
|
constexpr T val(2);
|
||||||
constexpr O o1; // disengaged
|
constexpr O o1; // disengaged
|
||||||
constexpr O o2{1}; // engaged
|
constexpr O o2{1}; // engaged
|
||||||
constexpr O o3{val}; // engaged
|
constexpr O o3{val}; // engaged
|
||||||
|
|
||||||
static_assert ( o1 < T(1) , "" );
|
static_assert ( (o1 < T(1)), "" );
|
||||||
static_assert ( !(o2 < T(1)), "" );
|
static_assert ( !(o2 < T(1)), "" ); // equal
|
||||||
static_assert ( !(o3 < T(1)), "" );
|
static_assert ( !(o3 < T(1)), "" );
|
||||||
static_assert ( o2 < T(2) , "" );
|
static_assert ( (o2 < val), "" );
|
||||||
static_assert ( o2 < T(val), "" );
|
static_assert ( !(o3 < val), "" ); // equal
|
||||||
static_assert ( o3 < T(3) , "" );
|
static_assert ( (o3 < T(3)), "" );
|
||||||
|
|
||||||
static_assert ( !(T(1) < o1), "" );
|
static_assert ( !(T(1) < o1), "" );
|
||||||
static_assert ( !(T(1) < o2), "" );
|
static_assert ( !(T(1) < o2), "" ); // equal
|
||||||
static_assert ( T(1) < o3 , "" );
|
static_assert ( (T(1) < o3), "" );
|
||||||
static_assert ( !(T(2) < o2), "" );
|
static_assert ( !(val < o2), "" );
|
||||||
static_assert (!(T(val) < o2), "" );
|
static_assert ( !(val < o3), "" ); // equal
|
||||||
static_assert ( !(T(3) < o3), "" );
|
static_assert ( !(T(3) < o3), "" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator!=(const optional<T>& x, const T& v);
|
||||||
|
// template <class T> constexpr bool operator!=(const T& v, const optional<T>& x);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<T> 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
|
||||||
|
}
|
@ -29,9 +29,9 @@ int main()
|
|||||||
constexpr O o1; // disengaged
|
constexpr O o1; // disengaged
|
||||||
constexpr O o2{1}; // engaged
|
constexpr O o2{1}; // engaged
|
||||||
|
|
||||||
static_assert ( nullopt == o1 , "" );
|
static_assert ( (nullopt == o1), "" );
|
||||||
static_assert ( !(nullopt == o2), "" );
|
static_assert ( !(nullopt == o2), "" );
|
||||||
static_assert ( o1 == nullopt , "" );
|
static_assert ( (o1 == nullopt), "" );
|
||||||
static_assert ( !(o2 == nullopt), "" );
|
static_assert ( !(o2 == nullopt), "" );
|
||||||
|
|
||||||
static_assert (noexcept(nullopt == o1), "");
|
static_assert (noexcept(nullopt == o1), "");
|
41
test/utilities/optional/optional.nullops/greater.pass.cpp
Normal file
41
test/utilities/optional/optional.nullops/greater.pass.cpp
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept;
|
||||||
|
// template <class T> constexpr bool operator>(nullopt_t, const optional<T>& x) noexcept;
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
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<T> 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
|
||||||
|
}
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator>=(const optional<T>& x, nullopt_t) noexcept;
|
||||||
|
// template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept;
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
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<T> 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
|
||||||
|
}
|
41
test/utilities/optional/optional.nullops/less_equal.pass.cpp
Normal file
41
test/utilities/optional/optional.nullops/less_equal.pass.cpp
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept;
|
||||||
|
// template <class T> constexpr bool operator<=(nullopt_t, const optional<T>& x) noexcept;
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
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<T> 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
|
||||||
|
}
|
@ -30,7 +30,7 @@ int main()
|
|||||||
constexpr O o2{1}; // engaged
|
constexpr O o2{1}; // engaged
|
||||||
|
|
||||||
static_assert ( !(nullopt < o1), "" );
|
static_assert ( !(nullopt < o1), "" );
|
||||||
static_assert ( nullopt < o2 , "" );
|
static_assert ( (nullopt < o2), "" );
|
||||||
static_assert ( !(o1 < nullopt), "" );
|
static_assert ( !(o1 < nullopt), "" );
|
||||||
static_assert ( !(o2 < nullopt), "" );
|
static_assert ( !(o2 < nullopt), "" );
|
||||||
|
|
||||||
|
41
test/utilities/optional/optional.nullops/not_equal.pass.cpp
Normal file
41
test/utilities/optional/optional.nullops/not_equal.pass.cpp
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept;
|
||||||
|
// template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept;
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
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<T> 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
|
||||||
|
}
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator>= (const optional<T>& x, const optional<T>& y);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<X> 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
|
||||||
|
}
|
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator> (const optional<T>& x, const optional<T>& y);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<X> 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
|
||||||
|
}
|
75
test/utilities/optional/optional.relops/less_equal.pass.cpp
Normal file
75
test/utilities/optional/optional.relops/less_equal.pass.cpp
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator<= (const optional<T>& x, const optional<T>& y);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
|
||||||
|
#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<X> 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
|
||||||
|
}
|
@ -43,20 +43,20 @@ int main()
|
|||||||
|
|
||||||
static_assert ( !(o1 < o1), "" );
|
static_assert ( !(o1 < o1), "" );
|
||||||
static_assert ( !(o1 < o2), "" );
|
static_assert ( !(o1 < o2), "" );
|
||||||
static_assert ( o1 < o3 , "" );
|
static_assert ( (o1 < o3), "" );
|
||||||
static_assert ( o1 < o4 , "" );
|
static_assert ( (o1 < o4), "" );
|
||||||
static_assert ( o1 < o5 , "" );
|
static_assert ( (o1 < o5), "" );
|
||||||
|
|
||||||
static_assert ( !(o2 < o1), "" );
|
static_assert ( !(o2 < o1), "" );
|
||||||
static_assert ( !(o2 < o2), "" );
|
static_assert ( !(o2 < o2), "" );
|
||||||
static_assert ( o2 < o3 , "" );
|
static_assert ( (o2 < o3), "" );
|
||||||
static_assert ( o2 < o4 , "" );
|
static_assert ( (o2 < o4), "" );
|
||||||
static_assert ( o2 < o5 , "" );
|
static_assert ( (o2 < o5), "" );
|
||||||
|
|
||||||
static_assert ( !(o3 < o1), "" );
|
static_assert ( !(o3 < o1), "" );
|
||||||
static_assert ( !(o3 < o2), "" );
|
static_assert ( !(o3 < o2), "" );
|
||||||
static_assert ( !(o3 < o3), "" );
|
static_assert ( !(o3 < o3), "" );
|
||||||
static_assert ( o3 < o4 , "" );
|
static_assert ( (o3 < o4), "" );
|
||||||
static_assert ( !(o3 < o5), "" );
|
static_assert ( !(o3 < o5), "" );
|
||||||
|
|
||||||
static_assert ( !(o4 < o1), "" );
|
static_assert ( !(o4 < o1), "" );
|
||||||
@ -68,7 +68,7 @@ int main()
|
|||||||
static_assert ( !(o5 < o1), "" );
|
static_assert ( !(o5 < o1), "" );
|
||||||
static_assert ( !(o5 < o2), "" );
|
static_assert ( !(o5 < o2), "" );
|
||||||
static_assert ( !(o5 < o3), "" );
|
static_assert ( !(o5 < o3), "" );
|
||||||
static_assert ( o5 < o4 , "" );
|
static_assert ( (o5 < o4), "" );
|
||||||
static_assert ( !(o5 < o5), "" );
|
static_assert ( !(o5 < o5), "" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
79
test/utilities/optional/optional.relops/not_equal.pass.cpp
Normal file
79
test/utilities/optional/optional.relops/not_equal.pass.cpp
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <optional>
|
||||||
|
|
||||||
|
// template <class T> constexpr bool operator!=(const optional<T>& x, const optional<T>& y);
|
||||||
|
|
||||||
|
#include <experimental/optional>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#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<T> 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user