Last active
October 6, 2016 13:20
-
-
Save htfy96/07173dd8be14f808b452a6937d548260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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