Thread overview
String front, back return code point/unit
Jun 23, 2021
vit
Jun 23, 2021
Tejas
Jun 23, 2021
vit
Jun 23, 2021
H. S. Teoh
June 23, 2021

Hello,

I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string).

C++ string has methods front, back and pop_back returning/deleting code units.
D strings has functions (std.range) front, back and popBack returning/deleting code points (autodecoding?).

Which behavior is better?

June 23, 2021

On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote:

>

Hello,

I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string).

C++ string has methods front, back and pop_back returning/deleting code units.
D strings has functions (std.range) front, back and popBack returning/deleting code points (autodecoding?).

Which behavior is better?

I think this video will be helpful:
https://www.youtube.com/watch?v=d3qY4dZ2r4w

There was also a discussion about this in the group: https://forum.dlang.org/thread/diexjstekiyzgxlicnts@forum.dlang.org

June 23, 2021

On Wednesday, 23 June 2021 at 15:48:57 UTC, Tejas wrote:

>

On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote:

>

Hello,

I am implementing @nogc string struct similar to c++ std::basic_string (link https://code.dlang.org/packages/basic_string).

C++ string has methods front, back and pop_back returning/deleting code units.
D strings has functions (std.range) front, back and popBack returning/deleting code points (autodecoding?).

Which behavior is better?

I think this video will be helpful:
https://www.youtube.com/watch?v=d3qY4dZ2r4w

There was also a discussion about this in the group: https://forum.dlang.org/thread/diexjstekiyzgxlicnts@forum.dlang.org

I wrongly formulated question.

My question is not about ranges/iterators but if is good idea autodecoding custom string or not.

June 23, 2021
On Wed, Jun 23, 2021 at 04:01:24PM +0000, vit via Digitalmars-d-learn wrote: [...]
> My question is not about ranges/iterators but if is good idea autodecoding custom string or not.

No.  Autodecoding is one of the decisions we regret because it introduces an unavoidable overhead on basically every string operation in Phobos.

Autodecoding was introduced under the misunderstanding that code point == grapheme, but unfortunately that is false.  So it fails to accomplish its original purpose and on top of that introduces a performance problem.  To accomplish its original purpose would require grapheme decoding; but unfortunately that introduces an even worse performance overhead (Unicode grapheme decoding is non-trivial).

tl;dr: don't do it.


T

-- 
Why are you blatanly misspelling "blatant"? -- Branden Robinson