From d51acb687313a1c7d651f999d7ad6d8fbd5ffa23 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 17 Mar 2017 00:41:09 -0300 Subject: [PATCH] Use C++17 fold expression macro This puts the fold expressions behind the feature macro instead of a general C++17 macro. It also adds a fold expression optimization to constexpr_sum (guarded by the same feature macro). --- include/pybind11/common.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 850aa61e6..73886e175 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