New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[container.reqmts] p65 seems to ban small string optimization #5518
Comments
@jwakely , the suggestion seems to be eminently reasonable. What do you think? |
It's as you just pointed out with The container requirements centralize exceptions. Elsewhere, where some [library] requirement is overriden, the exception is at the point of use, like
|
Hmm, N3108 solved this problem, but then that paragraph was removed in WP N3242 (see the red change marks in [basic.string] p3). I can't find any justification for removing that text. The editor's report in N3243 doesn't mention it. I can't find any paper or LWG issue saying to remove it. |
We had to put back the wording about |
That's not quite right. N3108 did not add the text about N3108 solved this problem, then some mystery edit in N3242 removed it (and the allocator stuff) and somehow nobody noticed. I'm quite concerned by this (LWG 2263 suggests there was another accidental deletion in N3242).
I don't think that's sufficient. That would allow us to copy characters when swapping strings, but it's not clear to me that "other than
Technically that only applies to containers in "this Clause", so already excludes I think we need an LWG issue, this is messy. |
That old Working Draft was just before we moved to git, so we can't really trace what caused the removal. |
[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 ofbasic_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-awareconstruct
anddestroy
requirements as well as a footnote stating this exception forswap
, but notes are non-normative. [string.require] p4 does not exemptswap
from the general rule allowing iterator invalidation by non-const member functions, and the footnote there does mentionswap
(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 thanarray
' in [container.reqmts] p65.The text was updated successfully, but these errors were encountered: