MCPcopy Create free account
hub / github.com/0voice/cpp_new_features / main

Function main

cpp_11/002_grammar_lamda.cpp:3–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <iostream>
2
3int main() {
4 int m = [](int x) { return [](int y) { return y * 2; }(x)+6; }(5);
5 std::cout << "m:" << m << std::endl;    //输出m:16
6
7 std::cout << "n:" << [](int x, int y) { return x + y; }(5, 4) << std::endl; //输出n:9
8
9 auto gFunc = [](int x) -> function<int(int)> { return [=](int y) { return x + y; }; };
10 auto lFunc = gFunc(4);
11 std::cout << lFunc(5) << std::endl;
12
13 auto hFunc = [](const function<int(int)>& f, int z) { return f(z) + 1; };
14 auto a = hFunc(gFunc(7), 8);
15
16 int a = 111, b = 222;
17 auto func = [=, &b]()mutable { a = 22; b = 333; std::cout << "a:" << a << " b:" << b << std::endl; };
18
19 func();
20 std::cout << "a:" << a << " b:" << b << std::endl;
21
22 a = 333;
23 auto func2 = [=, &a] { a = 444; std::cout << "a:" << a << " b:" << b << std::endl; };
24 func2();
25
26 auto func3 = [](int x) ->function<int(int)> { return [=](int y) { return x + y; }; };   
27 std::function<void(int x)> f_display_42 = [](int x) { print_num(x); };
28 f_display_42(44);
29}

Callers

nothing calls this directly

Calls 3

fFunction · 0.70
funcFunction · 0.70
func2Function · 0.50

Tested by

no test coverage detected