mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-11 06:27:22 +08:00
support bazel complie this project and format code.
This commit is contained in:
57
learn_class/modern_cpp_30/container2/relacontainer.cpp
Normal file
57
learn_class/modern_cpp_30/container2/relacontainer.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Created by light on 19-12-16.
|
||||
//
|
||||
|
||||
#include "../container1/output_container.h"
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
set<int> s{1, 1, 1, 2, 3, 4};
|
||||
cout << s << endl;
|
||||
|
||||
multiset<int, greater<int>> ms{1, 1, 1, 2, 3, 4};
|
||||
cout << ms << endl;
|
||||
|
||||
map<string, int> mp{{"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}};
|
||||
|
||||
cout << mp << endl;
|
||||
|
||||
mp.insert({"four", 4});
|
||||
cout << mp << endl;
|
||||
|
||||
cout << (mp.find("four") == mp.end()) << endl;
|
||||
|
||||
cout << (mp.find("five") == mp.end()) << endl;
|
||||
|
||||
mp["five"] = 5;
|
||||
|
||||
cout << mp << endl;
|
||||
|
||||
multimap<string, int> mmp{{"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}};
|
||||
|
||||
cout << mmp << endl;
|
||||
|
||||
mmp.insert({"four", -4});
|
||||
|
||||
cout << mmp << endl;
|
||||
|
||||
cout << (mp.find("four")->second) << endl;
|
||||
cout << (mp.lower_bound("four")->second) << endl;
|
||||
|
||||
cout << (mp.upper_bound("four")->second) << endl;
|
||||
cout << ((--mp.upper_bound("four"))->second) << endl;
|
||||
|
||||
multimap<string, int>::iterator lower, upper;
|
||||
std::tie(lower, upper) = mmp.equal_range("four");
|
||||
cout << (lower != upper) << endl; // 检测区间非空
|
||||
|
||||
cout << lower->second << endl;
|
||||
cout << (--upper)->second << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user