Commit 926e2cf3 by Jason Rhinelander

Add PYBIND11_EXPAND_SIDE_EFFECTS macro

This allows calling of functions (typically void) over a parameter
pack, replacing usage such as:

    bool unused[] = { (voidfunc(param_pack_arg), false)..., false };
    (void) unused;

with a much cleaner:

    PYBIND11_EXPAND_SIDE_EFFECTS(voidfunc(param_pack_arg));
parent 4e1e4a58
...@@ -504,6 +504,14 @@ struct is_input_iterator<T, void_t<decltype(*std::declval<T &>()), decltype(++st ...@@ -504,6 +504,14 @@ struct is_input_iterator<T, void_t<decltype(*std::declval<T &>()), decltype(++st
/// Ignore that a variable is unused in compiler warnings /// Ignore that a variable is unused in compiler warnings
inline void ignore_unused(const int *) { } inline void ignore_unused(const int *) { }
/// Apply a function over each element of a parameter pack
#ifdef __cpp_fold_expressions
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) (((PATTERN), void()), ...)
#else
using expand_side_effects = bool[];
#define PYBIND11_EXPAND_SIDE_EFFECTS(PATTERN) pybind11::detail::expand_side_effects{ ((PATTERN), void(), false)..., false }
#endif
NAMESPACE_END(detail) NAMESPACE_END(detail)
/// Returns a named pointer that is shared among all extension modules (using the same /// Returns a named pointer that is shared among all extension modules (using the same
......
...@@ -947,8 +947,7 @@ public: ...@@ -947,8 +947,7 @@ public:
set_operator_new<type>(&record); set_operator_new<type>(&record);
/* Register base classes specified via template arguments to class_, if any */ /* Register base classes specified via template arguments to class_, if any */
bool unused[] = { (add_base<options>(record), false)..., false }; PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
(void) unused;
/* Process optional arguments, if any */ /* Process optional arguments, if any */
process_attributes<Extra...>::init(extra..., &record); process_attributes<Extra...>::init(extra..., &record);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment