I have a std::map<std::string,foo>
and need to frequently find()
elements when instead of a std::string
, I have a const char*
. However, map.find("key_value")
won't work, I need a std::string
. So, I would need to map.find(std::string{"key_value"})
, but this will create a temporary std::string
(with its allocation and de-allocation) each time, making this potentially inefficient. Is this reasoning correct? If yes, how can I improve the situation?
I was think about using a wrapper around const char*
as key for the map which has its own comparison function and can be cheaply wrapped around any const char*
, no need for allocations. Is this a good idea? (note that my mapped values are not copyable, only movable).