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));
This commit is contained in:
Jason Rhinelander 2017-03-25 22:41:06 -03:00
parent 4e1e4a580e
commit 926e2cf333
2 changed files with 9 additions and 2 deletions

View File

@ -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
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)
/// Returns a named pointer that is shared among all extension modules (using the same

View File

@ -947,8 +947,7 @@ public:
set_operator_new<type>(&record);
/* Register base classes specified via template arguments to class_, if any */
bool unused[] = { (add_base<options>(record), false)..., false };
(void) unused;
PYBIND11_EXPAND_SIDE_EFFECTS(add_base<options>(record));
/* Process optional arguments, if any */
process_attributes<Extra...>::init(extra..., &record);