I know c++11 added some functions of what i mean, like std::to_string(). Its seems dead brained to not add something like that in as everyone useses it. But there are a ton more that are soo basic i am surprised that they are not in a standard library.
Like they have min(), but it can only take 2 arguments to check? So most of us are trying to throw in an entire array or vector and get the equivalent. min() doesnt help much if it can only take 2 args, as it would be just as easy to recreate the entire function to make it take an entire array or vector, etc.
and then there is std::stoi, which appears to have some problems i have seen. Not sure.
some basic functions:
join(), joining a vector/array into a string separated by some string delimiter
min(), max(), sum(), where it can take any size array or vector and retrieve the results
lstrip(), rstrip(), strip() strip off whitespace from left(l), right(r), or both sides but stopping on its first non-whitespace character
split(), split a string into an array or vector elements using whitespace as the delimiter and stripping off whitespace in the elements
listdir(), some kind of simple list directory
these seems like such most used functions that i cant believe they are not in the standard library of c++ or c++11, or are some and i missed it? Is there a reason to why they make you recreate simple functions over and over? I know boost has a lot of them, if not all of these options in it, but why has somehting like that not been added as a standard library?
I know c++11 added some functions of what i mean, like std::to_string(). Its seems dead brained to not add something like that in as everyone useses it.
You could accomplish the same thing (and more) before C++11 using std::ostringstream, but yeah, I agree that std::to_string is often convenient when it does what you want.
metulburr wrote:
Like they have min(), but it can only take 2 arguments to check? So most of us are trying to throw in an entire array or vector and get the equivalent. min() doesnt help much if it can only take 2 args, as it would be just as easy to recreate the entire function to make it take an entire array or vector, etc.
In C++11 they added versions of std::min that can take any number of elements.
and then there is std::stoi, which appears to have some problems i have seen. Not sure.
std::stoi was added in C++11. What's the problem with it? That it throws exceptions? Well, you can still use std::istringstream to convert a string to integer if you prefer.
For the rest of the functions (except listdir) they can be written easily yourself. C++ is a very general language that provides a lot of general functionality that is easy to reuse. It can't have easy-to-use functions for every eventuality. The reason PHP has a lot of the string functions you mentioned is because it is designed to be used to generate web pages where you work with strings all the time.
Peter87 took care of most questions, but to address the last one,
I know boost has a lot of them, if not all of these options in it, but why has something like that not been added as a standard library?
boost is the testing ground for the standard library, that's where ideas like that are reviwed, tested by the public, improved upon. If enough people find stuff from boost useful, it may get added to the standard library - it happened to about 20 of boost libraries (by my count) for C++11 , and, to name something from your list, it's happening to the filesystem library right now ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3693.html is the new draft for the standardized C++ filesystem library)
Remember, C++ has no reference implementation. When a boost library is turned into a standard requirement, every single vendor - GNU, Apple, Microsoft, Intel, IBM, Oracle, HP, etc, etc, has to spend time and effort to write their own implementation of that library. It's easy to change something in boost, it is almost impossible to change something in the standard library (we still have strstreams, deprecated in 1998!)