C++ Logo


Advanced search

Re: Please make string class more powerful

From: Scott Michaud <scott_at_[hidden]>
Date: Sat, 5 Sep 2020 19:55:40 -0400

Note: I am not on the standards committee.

Splitting a string with delimiters is possible through std::ranges,
although the literal way of getting a vector of strings involves
multiple dynamic allocations. Languages like Python and Java just eat
this cost, but (from what I see) C++ tends to back away from these
situations. You can use the building blocks that the standard library
does support to then compose the solution that's right for you.

Here's an example: https://godbolt.org/z/bq4Ms3 -- actually two examples.

It is inconvenient to need to compose a couple functions for each
project... but, for some users, so is using split() in these other
languages. (context: One of my jobs is making VR applications in Unity,
which is C#.) The difference is that they just don't really have a way
to make something better.

Of course, it's good to talk about the pain points and sharp edges. They
definitely exist.

On 9/5/2020 4:02 PM, 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.

Received on 2020-09-05 18:59:10