'unordered map - choosing a key type for a path
I would like to store a data (for simplicity let's assume that it will be integer id) in unordered_map based on the resource path. Here is an example function - a path is sent as const char*. The straightforward approach is to use std::string as a key:
std::unordered_map<std::string, int> ids;
void load(const char* path)
{
const int id = generateId(path);
ids[path] = id;
}
Paths may be too long for SSO. How can I optimize that code in C++17 ? Should I use string_view as a key:
std::unordered_map<std::string_view, int> ids;
?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
