I use exceptions heavily in my code, so I prefer to use at()
rather than find()
to find an element, but I just found that at()
seems not support std::string_view
, for example:
#include <map>
#include <iostream>
std::map<std::string, int, std::less<>> map{
{"one", 1},
{"two", 2},
};
const char* c = "onetwothree";
int main() {
std::string_view s(&c[3], 3);
std::cout << map.find(s)->second << std::endl;
std::cout << map.at(s) << std::endl; // will not compile
}
So can I use at()
with std::string_view
? Or in another word, can at()
support heterogeneous lookup?