/
githubmirror
/
CPlusPlusThings
Обзор
Документация
Войти
/
githubmirror
/
CPlusPlusThings
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
learn_class/modern_cpp_30/functionLambda/adder.cpp
32 строки
533 B
zhangxing
support bazel complie this project and format code.
30 мар 2024, 17:00
30 мар 2024, 17:00
3c8a3f2
Код
Авторство
О чём код?
// // Created by light on 20-1-11. // #include <iostream> using namespace std; struct adder { adder(int n) : n_(n) {} int operator()(int x) const { return x + n_; } private: int n_; }; int main() { auto add_2 = adder(2); // x+2 cout << add_2(3) << endl; auto t = bind1st(plus<int>(), 2); cout << t(1) << endl; // 上述的C++98 binder2nd<plus<int>> a2(plus<int>(), 2); cout << a2(3) << endl; cout << [](int x) { return x * x; }(3) << endl; return 0; // lambda表达式默认就是constexpr函数 }