c++14 new feature

2021/11 03 22:11

1、 lambda表达式广义捕获(generalized capture)

int apple = 100;
int dog = 200;
auto ap1 = [dog1=dog, apple1=apple] 
{
    printf("%d\n", apple1);
};
auto ap2 = [apple2 = &apple]
{
    printf("%d\n", *apple2);
};
apple++;
ap1();
ap2();

2、返回类型自动推导

auto add = [](auto x, auto y) 
{ 
    return x + y; 
};

void Chapter5()
{
    auto m = add(10L, 20L);
    auto s = add(std::string("a"), std::string("b"));
    printf("%d,%s\n", m, s.c_str());
}

3、二进制表达式的字面量

constexpr int val = 0b101;
printf("%d\n", val);

4、字符串表达式的字面量

std::string s = R"( c:\program\中\ )";
使用 R"(  和  )";

5、for循环

int arr[] = {1,2,3,4};
for(auto i: arr)
{
}

6、