diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 850aa61e..73886e17 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -401,7 +401,7 @@ template using bool_constant = std::integral_constant; template struct negation : bool_constant { }; /// Compile-time all/any/none of that check the boolean value of all template types -#ifdef PYBIND11_CPP17 +#ifdef __cpp_fold_expressions template using all_of = bool_constant<(Ts::value && ...)>; template using any_of = bool_constant<(Ts::value || ...)>; #elif !defined(_MSC_VER) @@ -444,9 +444,13 @@ struct void_type { }; template struct type_list { }; /// Compile-time integer sum +#ifdef __cpp_fold_expressions +template constexpr size_t constexpr_sum(Ts... ns) { return (0 + ... + size_t{ns}); } +#else constexpr size_t constexpr_sum() { return 0; } template constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); } +#endif NAMESPACE_BEGIN(constexpr_impl) /// Implementation details for constexpr functions