To increase the performance I'm trying to substitute std::string with custom specializations of std::basic_string where I'm replacing standard allocator with custom ones. One thing surprised me: the std::stoi class of functions requires constant references to std::string (or std::wstring) as an input, so these functions don't work with other specializations. But logically these functions shouldn't care of how the memory is allocated; so their signatures look overly limiting.
While I could use the std::from_chars to read integers from any string-like data, I still wonder whether there was a reason why std::stoi is designed that way, and whether there are other STL functions designed to work with std::basic_string templates.
Because it's just a proxy function to C
std::strtol(), converts its errors to C++ exceptions after a call to [1] [2]that takes only
char*, null-terminated char array, hence otherchar_typespecializations ofstd::basic_stringare not accepted.You can overload
strtolforstd::basic_stringwith your custom allocator, but you have to call it w/ostd::namespace qualification:As for
std::string_view, it is not required to refer a null-terminated string, thus it does not havestd::string_view::c_str()and itsdata()is not suitable forstd::strtol().