-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- struct LambdaFunctor {
- void operator() (int n) {
- cout << n << " ";
- }
- };
-
- int main() {
- vector <int> v;
-
- for (int i = 0; i < 10; ++i) {
- v.push_back(i);
- }
-
- for_each (v.begin(), v.end(), [] (int n) {
- cout << n << " ";
- });
- cout << endl;
-
- for_each (v.begin(), v.end(), LambdaFunctor());
- cout << endl;
-
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- if (a(1, 0)) {
- cout << 1 << endl;
- } else {
- cout << 0 << endl;
- }
- }
-
- int main() {
- test([] (int a, int b) {
- return a > b;
- });
- return 0;
- }
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- cout << a(1, 0) << endl;
- }
-
- int main() {
- test([] (int a, int b) -> int {
- if (a % 2 == 0) {
- return a * a * a;
- } else {
- return a / 2;
- }
- });
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
-
- struct LambdaFunctor {
- LambdaFunctor(int a, int b) : m_a(a), m_b(b) {}
-
- bool operator() () const {
- if (m_a % 2 == 0) {
- return m_a * m_a * m_a;
- } else {
- return m_a / 2;
- }
- }
-
- private:
- int m_a, m_b;
- };
-
- template <typename func>
- void test(func a) {
- cout << a() << endl;
- }
-
- int main() {
- int a = 1, b = 0;
-
- test([a, b] () -> int {
- if (a % 2 == 0) {
- return a * a * a;
- } else {
- return a / 2;
- }
- });
-
- test(LambdaFunctor(a, b));
- return 0;
- }
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- cout << a() << endl;
- }
-
- int main() {
- int a = 1, b = 0;
-
- test([=] () mutable -> int {
- if (a % 2 == 0) {
- a = 2;
- return a * a * a;
- } else {
- a = 4;
- return a / 2;
- }
- });
-
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- cout << a() << endl;
- }
-
- int main() {
- int a = 1;
-
- test([&a] () -> int {
- if (a % 2 == 0) {
- a = 2;
- return a * a * a;
- } else {
- a = 4;
- return a / 2;
- }
- });
-
- cout << a << endl;
- return 0;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- cout << a() << endl;
- }
-
- int main() {
- int a = 1;
-
- test([] {
- return 9;
- });
-
- return 0;
- }
-
-
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
-
- template <typename func>
- void test(func a) {
- cout << a() << endl;
- }
-
- #define mengxm [] () { cout << "mengxm" << endl; }
-
- int main() {
-
- mengxm();
-
- return 0;
- }