Agreed. Although I have occasionally written my own small libraries for handling strings, it would be nice to have one that's already written (and is probably better than anything I could write).
Also, since C++17 there's std::string_view which has much less baggage.
The container finds are a little easier using C++20 ranges - as the first and last iterator don't now have to be specified - just the container - although the return value still needs to be tested against .end():
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <ranges>
#include <vector>
#include <iostream>
int main()
{
std::vector<int> a;
// Populate a
if (std::ranges::find(a, 5) != a.end()) {
// Found
}
}
the performance of number to text and text to number in the default libraries on most systems are abysmal. You don't notice a few here and there but try doing over 100 million in a loop, the try doing it yourself, you can double, triple the speed or better.
its the 'pow' problem. The library functions do too much: the string ones support 30+ formats of numeric input, your data likely has 1 format. You can exploit that, and its a huge lift. Pow thinks all exponents are floating point and does a bunch of stuff to deal with that. You can exploit that for integer powers. General purpose tools are rarely as fast as specific purpose tools. Still, which do you use more often: integer power, or GCD? which one is in the language?
Yeah - that's why from_chars() and to_chars() were introduced with C++17.
I searched it up, the code needed to use these functions looks abysmal, like a step backwards. Making a custom function would probably be simpler when using strings.
One thing I've noticed about how the C++ standard does things is to make it consistent when it comes to iterators, etc. It might not be the simplest or easiest syntax, but it is similar no matter what part of the standard library is being referenced.
As "clunky" as the from_chars/to_chars syntax may be, it is consistent with other parts of the standard.