-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
31 lines (27 loc) · 810 Bytes
/
Copy pathmain.cpp
File metadata and controls
31 lines (27 loc) · 810 Bytes
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
#include <iostream>
#include <optional>
std::optional<int> test_optional () {
return std::nullopt;
}
int main () {
{
// 1. optional语法糖,可以直接判断返回是否有效,以下三种方法是等价的
if (auto res = test_optional()) {
// ...
}
if (auto res = test_optional(); res) {
// ...
}
if (auto res = test_optional(); res == std::nullopt) {
// ...
}
}
{
// C++ 14 的Raw字符串
std::string aaa = R"(asd "asdfas"""asdfasdfasdf" )";
std::cout << aaa << std::endl; // aaa是asd "asdfas"""asdfasdfasdf"
aaa = R"haha(这里面随便写“”""):)haha";
std::cout << aaa << std::endl; // aaa是这里面随便写“”""):
}
return 0;
}