diff --git a/libcxx/include/__type_traits/conjunction.h b/libcxx/include/__type_traits/conjunction.h --- a/libcxx/include/__type_traits/conjunction.h +++ b/libcxx/include/__type_traits/conjunction.h @@ -20,26 +20,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER > 14 - -template -struct __conjunction_impl { - using type = conditional_t::type>; -}; - -template -struct __conjunction_impl<_Arg> { - using type = _Arg; -}; - -template -struct conjunction : __conjunction_impl::type {}; - -template -inline constexpr bool conjunction_v = conjunction<_Args...>::value; - -#endif // _LIBCPP_STD_VER > 14 - template using __expand_to_true = true_type; @@ -52,6 +32,22 @@ template using _And _LIBCPP_NODEBUG = decltype(__and_helper<_Pred...>(0)); +#if _LIBCPP_STD_VER > 14 + +template +struct conjunction : true_type {}; + +template +struct conjunction<_Arg> : _Arg {}; + +template +struct conjunction<_Arg, _Args...> : conditional_t> {}; + +template +inline constexpr bool conjunction_v = conjunction<_Args...>::value; + +#endif // _LIBCPP_STD_VER > 14 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___TYPE_TRAITS_CONJUNCTION_H diff --git a/libcxx/test/std/utilities/meta/meta.logical/conjunction.compile.pass.cpp b/libcxx/test/std/utilities/meta/meta.logical/conjunction.compile.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.logical/conjunction.compile.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.logical/conjunction.compile.pass.cpp @@ -80,6 +80,13 @@ static_assert(!std::conjunction::value); static_assert(!std::conjunction_v); +// Also check the case where HasNoValue is not the last in the list (https://llvm.org/PR584900). +static_assert(!std::conjunction::value); +static_assert(!std::conjunction_v); + +static_assert(!std::conjunction::value); +static_assert(!std::conjunction_v); + static_assert(std::conjunction::value == -1); static_assert(std::conjunction_v); diff --git a/libcxx/test/std/utilities/meta/meta.logical/disjunction.compile.pass.cpp b/libcxx/test/std/utilities/meta/meta.logical/disjunction.compile.pass.cpp --- a/libcxx/test/std/utilities/meta/meta.logical/disjunction.compile.pass.cpp +++ b/libcxx/test/std/utilities/meta/meta.logical/disjunction.compile.pass.cpp @@ -80,6 +80,13 @@ static_assert(std::disjunction::value); static_assert(std::disjunction_v); +// Also check the case where HasNoValue is not the last in the list (https://llvm.org/PR584900). +static_assert(std::disjunction::value); +static_assert(std::disjunction_v); + +static_assert(std::disjunction::value); +static_assert(std::disjunction_v); + static_assert(std::disjunction::value == -1); static_assert(std::disjunction_v);