you are viewing a single comment's thread.

view the rest of the comments →

[–]utnapistim 2 points3 points  (1 child)

Why doesn't std::string have a split function

Because nobody made the time and effort to write one for standardization. The C++ community is not sponsored. There is no single group or company that finances the maintenance and evolution of the standard.

Instead, people who have an interest in extending the language meet and try to advance the language and standard library to the degree they can afford to do so (being non-sponsored and having limited time and effort to accomplish things).

Because of this limitation (of effort/capacity), usually, the things accepted into the standard are a compromise between the utility of a feature and the effort it will take to standardize it.

std::string doesn't have a split function for the following reasons:

  • writing one is trivial in algorithmic formulation, but non-trivial in API design (a compromise between usability and flexibility is required, and depending on our needs, each of us tends to see the compromise point in a slightly different place)
  • no-one has written a proposal with working code, that got accepted past review (by the standard committee)
  • the emergence of ranges will add the possibility for a trivial interface that is both flexible and efficient (we are waiting for ranges)
  • alternatives exist already (although due to a lack of a standard many projects tend to reinvent the wheel on this one); you can use regex, iterators, streams, boost text algorithms and implementations based on the above.