I wanted to understand the specific optimization if any which can be performed by the compiler here .
The two get functions get() return a string by refrence and another by value . Map is global in nature .
std::map<std::string, std::string> value;
std::string& get(std::string& key) {
    return value[key];
}
std::string get2(std::string& key) {
    return value[key];
}
int main()
{ 
    value.insert(std::make_pair("name","XXXXXXX"));
    std::string keyaa = "name";
    auto new_val = get(keyaa);
    auto new_val2 = get2(keyaa);
}
Aucun commentaire:
Enregistrer un commentaire