Looking up c-string key in `std::string`-keyed hash

Viewed 76

I have std::unordered_map<std::string, MyType>.

I get a char const* key, which I need to look up. Is there anyway to do it without constructing std::string(key) to avoid memory copy?

As I understand, C++20 allows it:

std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::find :

      template<class K> iterator find( const K& x );

So I can use std::string_view as K. Any way to do it in C++17?

0 Answers
Related