mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-30 00:47:12 +00:00
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).
This commit is contained in:
parent
efa8726ff7
commit
d51acb6873
@ -401,7 +401,7 @@ template <bool B> using bool_constant = std::integral_constant<bool, B>;
|
|||||||
template <typename T> struct negation : bool_constant<!T::value> { };
|
template <typename T> struct negation : bool_constant<!T::value> { };
|
||||||
|
|
||||||
/// Compile-time all/any/none of that check the boolean value of all template types
|
/// Compile-time all/any/none of that check the boolean value of all template types
|
||||||
#ifdef PYBIND11_CPP17
|
#ifdef __cpp_fold_expressions
|
||||||
template <class... Ts> using all_of = bool_constant<(Ts::value && ...)>;
|
template <class... Ts> using all_of = bool_constant<(Ts::value && ...)>;
|
||||||
template <class... Ts> using any_of = bool_constant<(Ts::value || ...)>;
|
template <class... Ts> using any_of = bool_constant<(Ts::value || ...)>;
|
||||||
#elif !defined(_MSC_VER)
|
#elif !defined(_MSC_VER)
|
||||||
@ -444,9 +444,13 @@ struct void_type { };
|
|||||||
template <typename...> struct type_list { };
|
template <typename...> struct type_list { };
|
||||||
|
|
||||||
/// Compile-time integer sum
|
/// Compile-time integer sum
|
||||||
|
#ifdef __cpp_fold_expressions
|
||||||
|
template <typename... Ts> constexpr size_t constexpr_sum(Ts... ns) { return (0 + ... + size_t{ns}); }
|
||||||
|
#else
|
||||||
constexpr size_t constexpr_sum() { return 0; }
|
constexpr size_t constexpr_sum() { return 0; }
|
||||||
template <typename T, typename... Ts>
|
template <typename T, typename... Ts>
|
||||||
constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
|
constexpr size_t constexpr_sum(T n, Ts... ns) { return size_t{n} + constexpr_sum(ns...); }
|
||||||
|
#endif
|
||||||
|
|
||||||
NAMESPACE_BEGIN(constexpr_impl)
|
NAMESPACE_BEGIN(constexpr_impl)
|
||||||
/// Implementation details for constexpr functions
|
/// Implementation details for constexpr functions
|
||||||
|
Loading…
Reference in New Issue
Block a user