cplusplus / cplusplus/draft

[container.reqmts] p65 seems to ban small string optimization

Open
#5,518 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

[container.reqmts] p65 (previously at [container.requirements.general] p9 in C++11–20) states that, except for array in particular, a.swap(b) shall not copy, move, or swap any container elements, and preserves iterator stability. However, [basic.string.general] p2 states that specializations of basic_string are contiguous containers. SSO would mean that both requirements of p65 are impossible to satisfy, as if either string is small, the elements must be copied from the internal buffer of that string into the internal buffer of the other string, even if such copying is trivial.

LWG1415 described an overlapping issue, and was resolved by N3108, which added normative wording exempting basic_string from the allocator-aware construct and destroy requirements as well as a footnote stating this exception for swap, but notes are non-normative. [string.require] p4 does not exempt swap from the general rule allowing iterator invalidation by non-const member functions, and the footnote there does mention swap (seemingly being a less specific version of the note suggested by N3108, though it may be unrelated), however, it is not clear to me that it should override the invalidation guarantees in [container.reqmts] p65 (is a general rule about many operations on a specific container more specific than a more descriptive rule about a specific member function of many containers, particularly one which does specify an exception?), and it definitely doesn't override the complementary restriction on element copy, move, or swap operations stated there that SSO also necessarily violates, because there is no wording in [basic.string] that mentions swap performing or not performing those operations.

The simplest resolution is to simply add 'and basic_string' after 'other than array' in [container.reqmts] p65.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading [container.reqmts] p65, [basic.string.general] p2, and [string.require] p4 in the draft, then compare the related resolution in N3108 and LWG1415. Done means resolving whether basic_string needs an explicit swap exception so the standard's iterator and element-operation requirements are consistent with SSO.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.