Fold operators
A good example of fold expression [1] usage is the following. In case you have a member defined as this:
std::tuple<Handler<Events>...> pool;
at some point, you’ll fall in need of operating on every Handler<Events>
instance saved in the pool. This is currently very easy to be written leveraging the fold expression as this:
void clear() noexcept {
std::apply([](auto &&... args) {
((args.clear()), ...);
}, pool);
}
This is far shorter than range-loop and std::for_each
. It costs a bit in readability, though.
Reference
1) https://en.cppreference.com/w/cpp/language/fold
2) https://github.com/stefanofiorentino/pool_type.git