Skip to content

Instantly share code, notes, and snippets.

@htfy96
Last active October 6, 2016 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htfy96/07173dd8be14f808b452a6937d548260 to your computer and use it in GitHub Desktop.
Save htfy96/07173dd8be14f808b452a6937d548260 to your computer and use it in GitHub Desktop.
// Compile this with C++11: -std=c++11
#include <utility>
#include <iostream>
#include <vector>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef int (*FType)(int);
int runtime(const vector<FType>& fv)
{
// do something
return fv.size();
}
template<typename ... T>
int runtime_wrapper(T&& ... args)
{
vector<FType> v = { std::forward<T>(args)... }; // perfect forwarding
return runtime(v);
}
int f1(int) {}
int f2(int) {}
int main()
{
cout << runtime_wrapper(f1) << endl;
cout << runtime_wrapper(f1, f2) << endl;
// cout << runtime_wrapper(2) << endl; // Strong-typed, only accept FType
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment