:string用于插入,而将str_view仅用于查找,则可以将std::string构造函数设为深层,而将str_view构造...
1 #include <iostream> 2 #include <string> 3 #include <unordered_map> 4 #include <functional> 5 using namespace std; 6 7 class Person{ 8 public: 9 string name; 10 int age; 11 12 Person(string n, int a){ 13 name = n; 14 age = a; 15 } 16 }; 17 18 namespace std{ 19 t...
#include <iostream> #include <unordered_map> std::unordered_map <std::string_view, int> myDictionary{}; void addEmployee(std::string_view newName, int newTime) { // first check if they name already exists, if it does then do nothing and return auto it{std::find_if(myDictionary.begi...
str(); } std::string msg; }; enum class LogLevel{ Info = 0, }; void log(LogLevel level, std::string_view msg, std::initializer_list<LogPair> args){ (void)level;//TODO std::cout<<msg<<'\n'; for(const LogPair& s: args) std::cout<<'\t'<<s.msg<<'\n'; } struct Tes...