C++ Logo


Advanced search

Re: Please make string class more powerful

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Sun, 6 Sep 2020 03:36:56 +0300
On 2020-09-05 23:02, Jicun Hu via Std-Proposals wrote:
> Compared to string processing in Python or Java, the string class in C++
> is way too weak.
> For simple tasks such as splitting a string with delimiters, making all
> characters uppercase or lowercase, etc., we need to write our own
> functions. This makes programming in C++ inconvenient.

While I agree that the operations you mention are useful, I do not think
bringing them into std::string itself is a good idea. std::string is a
monstrous all-in-one class already, which is bad as it is. Having some
of the operations as free functions would allow to apply them to other
string types and would make std::string more lightweight in terms of
implementation cost, inclusion cost and dependencies. For instance, case
conversion would probably add a dependency on locale.

IMHO, an ideal std::string would be just a container of characters (i.e.
bytes) with added syntax sugar for string concatenation, comparison,
c_str(), substr(), but not much more than that. The rest would be
external algorithms defined in a separate header.

Received on 2020-09-05 19:40:30