Run Callable on each Argument

This snippet shows how to run a callable given as first argument on each following argument.

template<typename F, typename ...T>
void for_each_arg(F&& function, T&&... args){
    //(function(std::forward(args)), ...); // c++17 fold expression
    int pass[]{ ((   function(std::forward(args))   ), 0)... };
    (void)pass;
}
Posted in c++

Leave a Reply

Your email address will not be published. Required fields are marked *