#include <utility> #include <iostream> template<typename T, typename... Args> auto sum(T (*F) (T, const T &), Args&&... args) // -> decltype(F(std::forward<Args>(args)...)) // for C++ 11 { return F(std::forward<Args>(args)...); } int main() { auto func = [](int a, int const& b) { return a += b; }; int i = 4; sum(func, i, 2); std::cout << i << std::endl; return 0; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)