Say I have such simple functions:
struct Data {
string name;
string value; // Can be very long
};
// Use Data directly to avoid copy. (Not Data*)
unordered_map<size_t, Data> g_data;
// Should I use "const string& name, const string& value"?
void addData(string name, string value) {
// Should I use any std::move? Like:
// ... = {std::move(name), std::move(value)};
g_data[hash(name, value)] = {name, value};
}
// Returning as string seems obvious.
string generateData() {
// Some computation...
return value;
}
void test() {
addData(generateName(), generateDatA());
}
I know that the above code works. But I'm wondering whether I should use const string& in addData? I also wonder std::move can make it more efficient?
I'm using at least C++14, and C++17 is also enabled.