I trying to write a function (call it apply_args()) that takes a specific function or function object and arguments for calling this object, and calls it using the perfect forwarding.
Example:
auto fun = [](std::string a, std::string const& b) { return a += b; };
std::string s("world!");
// s is passing by lvalue ref,
// temporary object by rvalue ref
s = apply_args(fun, std::string("Hello, "), s);
How can I implement that function?
template <typename Func, typename ...Args>
decltype(auto) apply_args(Func &&f, Args &&...args) {
return f(std::forward<Args>(args)...);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With