From 04295354b0f0f101773c4f9437680d45a70bab24 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 7 Feb 2025 15:40:16 +0100 Subject: [PATCH] Revert "[libc++] Reduce std::conjunction overhead (#124259)" It turns out that the new implementation takes significantly more stack memory for some reason. This reverts commit 2696e4fb9567d23ce065a067e7f4909b310daf50. (cherry picked from commit 0227396417d4625bc93affdd8957ff8d90c76299) --- libcxx/include/__type_traits/conjunction.h | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/libcxx/include/__type_traits/conjunction.h b/libcxx/include/__type_traits/conjunction.h index 6b6717a50a468..ad9656acd47ec 100644 --- a/libcxx/include/__type_traits/conjunction.h +++ b/libcxx/include/__type_traits/conjunction.h @@ -10,6 +10,8 @@ #define _LIBCPP___TYPE_TRAITS_CONJUNCTION_H #include <__config> +#include <__type_traits/conditional.h> +#include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> #include <__type_traits/is_same.h> @@ -19,29 +21,22 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template -struct _AndImpl; +template +using __expand_to_true _LIBCPP_NODEBUG = true_type; -template <> -struct _AndImpl { - template - using _Result _LIBCPP_NODEBUG = - typename _AndImpl::template _Result<_First, _Rest...>; -}; +template +__expand_to_true<__enable_if_t<_Pred::value>...> __and_helper(int); -template <> -struct _AndImpl { - template - using _Result _LIBCPP_NODEBUG = _Res; -}; +template +false_type __and_helper(...); // _And always performs lazy evaluation of its arguments. // // However, `_And<_Pred...>` itself will evaluate its result immediately (without having to // be instantiated) since it is an alias, unlike `conjunction<_Pred...>`, which is a struct. // If you want to defer the evaluation of `_And<_Pred...>` itself, use `_Lazy<_And, _Pred...>`. -template -using _And _LIBCPP_NODEBUG = typename _AndImpl::template _Result; +template +using _And _LIBCPP_NODEBUG = decltype(std::__and_helper<_Pred...>(0)); template struct __all_dummy; @@ -51,11 +46,22 @@ struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)... #if _LIBCPP_STD_VER >= 17 -template -struct _LIBCPP_NO_SPECIALIZATIONS conjunction : _And<_Args...> {}; +template +struct _LIBCPP_NO_SPECIALIZATIONS conjunction : true_type {}; + +_LIBCPP_DIAGNOSTIC_PUSH +# if __has_warning("-Winvalid-specialization") +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization") +# endif +template +struct conjunction<_Arg> : _Arg {}; + +template +struct conjunction<_Arg, _Args...> : conditional_t> {}; +_LIBCPP_DIAGNOSTIC_POP template -_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool conjunction_v = _And<_Args...>::value; +_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool conjunction_v = conjunction<_Args...>::value; #endif // _LIBCPP_STD_VER >= 17