python: | c++17: | get | set | extend/update | find | index | size | loop |
list | std::vector | v[0]; | v.emplace_back("a"); v.push_back("a"); v[0] = "a"; v.insert(v.begin()+1, "a"); | dest_v.insert(dest_v.end(), src_v.begin(), src_v.end()); | it = find (v.begin(), v.end(), 30); if (it != v.end()) std::cout << "found in v: " << *it << '\n'; | it = find (v.begin(), v.end(), 30); if (it != v.end()) std::cout << "index in v: " << it - v.begin() << '\n'; | v.size(); | for(unsigned int i = 0; i < my_vec.size(); ++i) my_vec[i]->do_something(); |
std::list | l.append("a"); | l.pop(0); | l.index("a"); | |||||
std::array<char, 9> vals = { 2, 1, 2, 1, 3, 1, 2, 1, 2 }; | ||||||||
int RANKS[] = {2, 1, 2, 1, 3, 1, 2, 1, 2}; | ||||||||
tuple | std::vector | |||||||
dict | std::map<std::string, double> myMap({{"red",4},{"blue",10},{"green",2}}); | for (auto& vp : myMap)sum+=vp.second; for (auto& vp : myMap)prod*=vp.first; | ||||||
std::unordered_map<std::string, int> dict = {{"one", 1}, {"two", 2}}; | int v = dict["aaa"]; for (const auto& pair : dict) std::cout << pair.first << ": " << pair.second << '\n'; | letter_counts['b'] = 42; // update existing value letter_counts['x'] = 9; // insert new value m.emplace("k", "v"); | dest_map.merge(src_map); | auto search = example.find("key"); if(search != example.end()) std::cout << "Found " << search->first << " " << search->second << '\n'; | m.size(); | auto iter = docids_set.find(doc_id); if (iter != docids_set.end()) { if (iter->second > weight) continue;} | ||
set | std::unordered_set stopwords = {"的", "了", "呢", "啊", "怎么", "什么", "怎样", "是", "要"}; | level_1st_qt.insert(UserQueryType"); | auto search = example.find(2); if(search != example.end()) std::cout << "Found " << (*search) << '\n'; | s.size(); | for (auto& v : level_1st_qt) do_something(v); |