diff --git a/libcxx/include/optional b/libcxx/include/optional index c325140ee66f2..db236f86e74dd 100644 --- a/libcxx/include/optional +++ b/libcxx/include/optional @@ -672,44 +672,41 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&) = default; _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {} - template < - class _InPlaceT, - class... _Args, - class = enable_if_t< _And< _IsSame<_InPlaceT, in_place_t>, is_constructible >::value > > + template , is_constructible>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args) : __base(in_place, std::forward<_Args>(__args)...) {} template &, _Args...>> > + enable_if_t&, _Args...>, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) : __base(in_place, __il, std::forward<_Args>(__args)...) {} - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {} - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) : __base(in_place, std::forward<_Up>(__v)) {} // LWG2756: conditionally explicit conversion from const optional<_Up>& - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(const optional<_Up>& __v) { this->__construct_from(__v); } - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(const optional<_Up>& __v) { this->__construct_from(__v); } // LWG2756: conditionally explicit conversion from optional<_Up>&& - template ::template __enable_implicit<_Up>(), int> = 0> + template ::template __enable_implicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional(optional<_Up>&& __v) { this->__construct_from(std::move(__v)); } - template ::template __enable_explicit<_Up>(), int> = 0> + template ::template __enable_explicit<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit optional(optional<_Up>&& __v) { this->__construct_from(std::move(__v)); } @@ -718,7 +715,7 @@ public: template ::value, int> = 0> + enable_if_t<_IsSame<_Tag, __optional_construct_from_invoke_tag>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Tag, _Fp&& __f, _Args&&... __args) : __base(__optional_construct_from_invoke_tag{}, std::forward<_Fp>(__f), std::forward<_Args>(__args)...) {} # endif @@ -732,12 +729,12 @@ public: _LIBCPP_HIDE_FROM_ABI constexpr optional& operator=(optional&&) = default; // LWG2756 - template < - class _Up = value_type, - class = enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Up>, optional>, - _Or< _IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not> >, - is_constructible, - is_assignable >::value> > + template , optional>, + _Or<_IsNotSame<__remove_cvref_t<_Up>, value_type>, _Not>>, + is_constructible, + is_assignable>::value, + int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(_Up&& __v) { if (this->has_value()) this->__get() = std::forward<_Up>(__v); @@ -747,21 +744,20 @@ public: } // LWG2756 - template ::template __enable_assign<_Up>(), int> = 0> + template ::template __enable_assign<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(const optional<_Up>& __v) { this->__assign_from(__v); return *this; } // LWG2756 - template ::template __enable_assign<_Up>(), int> = 0> + template ::template __enable_assign<_Up>(), int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 optional& operator=(optional<_Up>&& __v) { this->__assign_from(std::move(__v)); return *this; } - template > > + template , int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) { reset(); this->__construct(std::forward<_Args>(__args)...); @@ -770,7 +766,7 @@ public: template &, _Args...> > > + enable_if_t&, _Args...>, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) { reset(); this->__construct(__il, std::forward<_Args>(__args)...); @@ -982,17 +978,15 @@ public: using __base::reset; }; -# if _LIBCPP_STD_VER >= 17 template optional(_Tp) -> optional<_Tp>; -# endif // Comparisons between optionals -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { if (static_cast(__x) != static_cast(__y)) return false; if (!static_cast(__x)) @@ -1000,11 +994,11 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x == *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (static_cast(__x) != static_cast(__y)) return true; if (!static_cast(__x)) @@ -1012,11 +1006,11 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x != *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__y)) return false; if (!static_cast(__x)) @@ -1024,11 +1018,11 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x < *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__x)) return false; if (!static_cast(__y)) @@ -1036,11 +1030,11 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x > *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__x)) return true; if (!static_cast(__y)) @@ -1048,11 +1042,11 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) { return *__x <= *__y; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const optional<_Up>& __y) { if (!static_cast(__y)) return true; if (!static_cast(__x)) @@ -1145,99 +1139,99 @@ _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const optional<_Tp>& # endif // _LIBCPP_STD_VER <= 17 // Comparisons with T -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x == __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() == std::declval()), bool>, - bool > -operator==(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() == std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v == *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x != __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() != std::declval()), bool>, - bool > -operator!=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() != std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v != *__x : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x < __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() < std::declval()), bool>, - bool > -operator<(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() < std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v < *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x <= __v : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() <= std::declval()), bool>, - bool > -operator<=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() <= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v <= *__x : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x > __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() > std::declval()), bool>, - bool > -operator>(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() > std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v > *__x : true; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const optional<_Tp>& __x, const _Up& __v) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const optional<_Tp>& __x, const _Up& __v) { return static_cast(__x) ? *__x >= __v : false; } -template -_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t< - is_convertible_v() >= std::declval()), bool>, - bool > -operator>=(const _Tp& __v, const optional<_Up>& __x) { +template < + class _Tp, + class _Up, + enable_if_t() >= std::declval()), bool>, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const _Tp& __v, const optional<_Up>& __x) { return static_cast(__x) ? __v >= *__x : true; } @@ -1252,9 +1246,8 @@ operator<=>(const optional<_Tp>& __x, const _Up& __v) { # endif // _LIBCPP_STD_VER >= 20 -template -inline _LIBCPP_HIDE_FROM_ABI -_LIBCPP_CONSTEXPR_SINCE_CXX20 enable_if_t< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, void > +template && is_swappable_v<_Tp>, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); }