Skip to content

<sstream>: Change the underlying buffer of basic_stringbuf to basic_string #938

@Berrysoft

Description

@Berrysoft

See: #919 (comment)

The underlying buffer of basic_stringbuf is simply an array, which makes implementing P0408R7 hard.

When there's an rvalue of basic_string received, we cannot simply replace the current buffer with the string buffer:

  • basic_string uses SSO (small string optimization). When it is in small mode, the string should be copied to the current buffer;
  • In readonly mode, basic_stringbuf doesn't recognize the reserved space of the string, which means we should copy the string non-conditionally.

When we want the basic_string from an rvalue of basic_stringbuf, we cannot simply construct a basic_string from the current buffer:

  • The current buffer is not zero-terminated. When the buffer is already full, we should copy the buffer to a basic_string;
  • It loses SSO, because basic_stringbuf doesn't uses SSO.

We could see that the current implementation will cause a lot of copying. I think it should be fixed in vNext.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    vNextBreaks binary compatibility

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions