From cafae0561920883f3269aa9a89aa4035b6a226e1 Mon Sep 17 00:00:00 2001 From: Christopher Di Bella Date: Tue, 22 Jun 2021 19:21:46 +0000 Subject: [PATCH] [libcxx][NFC] prepares `` for moving out forward and swap * `` depends on `std::forward`, so we replaced it with `static_cast`. * `swap`'s return type is confusing, so it's been rearranged to improve readabilitiy. --- libcxx/include/type_traits | 43 +++++++++++++++++++++---------------------- libcxx/include/utility | 22 +++++++++++----------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 4e5a6ba..2593549 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -2855,7 +2855,7 @@ __decay_copy(_Tp&& __t) noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp>>) #endif { - return _VSTD::forward<_Tp>(__t); + return static_cast<_Tp&&>(__t); } template @@ -3866,42 +3866,42 @@ template (__a0).*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...)) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...)) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)) // bullets 4, 5 and 6 @@ -3910,14 +3910,14 @@ template (__a0).*__f) +_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _A0&& __a0) -_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f) +_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f) template > @@ -3938,14 +3938,14 @@ template (__a0)).*__f) +_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f) template > inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _A0&& __a0) -_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f) +_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f) // bullet 7 @@ -3953,13 +3953,13 @@ template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __invoke(_Fp&& __f, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)) template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR auto __invoke_constexpr(_Fp&& __f, _Args&& ...__args) -_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...)) +_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)) #undef _LIBCPP_INVOKE_RETURN @@ -4195,18 +4195,17 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2); -template -inline _LIBCPP_INLINE_VISIBILITY #ifndef _LIBCPP_CXX03_LANG -typename enable_if -< - is_move_constructible<_Tp>::value && - is_move_assignable<_Tp>::value ->::type +template +using __swap_result_t = typename enable_if::value && is_move_assignable<_Tp>::value>::type; #else -void +template +using __swap_result_t = void; #endif -_LIBCPP_CONSTEXPR_AFTER_CXX17 + +template +inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp> swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value && is_nothrow_move_assignable<_Tp>::value) { diff --git a/libcxx/include/utility b/libcxx/include/utility index 1060b5c..c536a1a 100644 --- a/libcxx/include/utility +++ b/libcxx/include/utility @@ -272,19 +272,19 @@ operator>=(const _Tp& __x, const _Tp& __y) // move_if_noexcept -template -_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 #ifndef _LIBCPP_CXX03_LANG -typename conditional -< - !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, - const _Tp&, - _Tp&& ->::type -#else // _LIBCPP_CXX03_LANG -const _Tp& +template +using __move_if_noexcept_result_t = + typename conditional::value && is_copy_constructible<_Tp>::value, const _Tp&, + _Tp&&>::type; +#else // _LIBCPP_CXX03_LANG +template +using __move_if_noexcept_result_t = const _Tp&; #endif -move_if_noexcept(_Tp& __x) _NOEXCEPT + +template +_LIBCPP_NODISCARD_EXT inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +__move_if_noexcept_result_t<_Tp> move_if_noexcept(_Tp& __x) _NOEXCEPT { return _VSTD::move(__x); } -- 2.7.4