Functional Programming
std Function 사용법 예제
hellobird
2019. 3. 23. 12:49
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <QCoreApplication> #include <iostream> #include <functional> using namespace std; template <typename T> auto co_T(T t_) -> decltype (t_){ cout << typeid (t_).name() << " : " << t_ << endl; return t_; } template<typename T> auto add(T _t1, T _t2, function<int(T, T)> _fx){ return _fx(_t1, _t2); } int main(int argc, char *argv[]) { int r = add<int>(1, 2 , [](int x, int y){ return x + y ;}); co_T(r); return 0; } | cs |