C++11???????????????????
???????????? ???????[ 2016/6/22 11:01:48 ] ??????????????????? .NET
????????C++11??????????????????????????????????Щ?????????
????????toy code??????????????????o?????????
??????????
????long long????
????C++11????????????long long??????????????С??long???????????????£?
????long large = LONG_MAX;
????long long long_large = LLONG_MAX;
????long long long_long_large = 1LL << 63;
????cout<<"test long long??"<<large<<' '<<long_large<<' '<<long_long_large<<endl;
?????????????????long long?????long??????????64bit???
????nullptr??????
????C++11????????????????????nullptr????????????????????NULL????0????????
????int *p1 = nullptr;
????int *p2 = 0;
????int *p3 = NULL;
????cout<<"test nullptr: "<<(p1 == p2)<<' '<<(p1 == p3)<<endl;
?????????????nullptr??NULL??0????????
????constexpr
????C++11?????????constexpr???????????????????????????????????????????????????????
????int out_i = 0; // out_i????????????
????...
????constexpr int mf = 20;
????constexpr int limit = mf + 1;
????constexpr int *p4 = &out_i;
????// the following would cause a make error
????// since large is not a constexpr
????//constexpr int wrong = large + 1;
????// since &in_j is not a constexpr;
????//int in_j = 0;
????//constexpr int *p5 = &in_j;
??????????????constexpr??????????????????????????????????????????????????????????????????????????????
?????????????constexpr?????const??????????????????
????constexpr int *p6 = nullptr; // a const pointer point to an int
????// p6 = &out_i; // error: p6 is a constexpr
????const int *p7 = nullptr; // a pointer point to a const int
????????????????????????????????????????????????????????const int??????????????????????
????constexpr???????????????constexpr????????????????????????????????????????????
????a.???????????????????
????b.?β????????????????
????c.???????б?????????????return???
????constexpr int sz() { return 42; }
????constexpr int new_sz(int cnt) { return sz() * cnt; }
????constexpr int size = sz();
????constexpr int nsize = new_sz(mf);
????//constexpr int wrong_size = new_sz(out_i); // error: out_i is not a constexpr
????cout<<"test constexpr: "<<mf<<' '<<limit<<' '<<p4<<' '<<size<<' '<<nsize<<' '<<p6<<' '<<p7<<endl;
????noexcept
????noexcept??????????????????????????????????????????????????????????noexcept?????????????????????????????????????noexcept???????????????????????????????????????????
????void no_except() noexcept
????{
????throw 1;
????}
????// the following call will cause terminate
????//no_except();
????noexcept?????????????noexcept(true)??????????????noexcept(false)??????????????
??????noexcept????????????????????????????????????????bool???????????????noexcept????????????????ν????????
??????noexcept?????????????????noexcept???????????????3??÷???
????void no_except2() noexcept(noexcept(no_except())){}
????cout<<"test noexcept: "<<noexcept(no_except())<<' '<<noexcept(no_except2())<<endl;
?????????÷????no_except2??no_except???????????????
?????????
?????б?????
????C++11?±???????????????????б???????????
???????????б????????????????
????int single_int1 = 0;
????int single_int2 = {0};
????cout<<"test list initialization:
"<<single_int1<<' '<<single_int2<<endl;
???????????б??????????????vector??list??map??set…)??
// vector/list list initialization
vector<string> v1 = {"ab"?? "cd"?? "ef"};
list<string> l2{"gh"?? "ij"?? "kl"};
//vector<string> v3("mn"?? "op"?? "qr"); // wrong initialization format
cout<<"test vector/list list initialization:
"<<v1[1]<<' '<<l2.front()<<endl;
// map/set list initialization
map<string?? string> m1 =
{
{"a"?? "A"}??
{"b"?? "B"}??
{"c"?? "C"}
};
m1.insert({"d"?? "D"});
set<string> s1 = {"a"?? "b"?? "c"};
cout<<"test map/set list initialization:
"<<m1["d"]<<' '<<*s1.find("b")<<endl;
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11