Created on 2012-04-13.00:00:00 last changed 90 months ago
Proposed resolution:
Apply P0178.
[ 2017-06-02 Issues Telecon ]
Leave as LEWG; priority 3
[ 2017-02 in Kona, LEWG responds ]
Note in the issue that this is tracked here
[ 2016-03 Jacksonville ]
Alisdair says that his paper P0178 addresses this.
[ 2012-10 Portland: Move to Open ]
The issue is broader than containers with stateful allocotors, although they are the most obvious example contained within the standard itself. The basic problem is that once you have a stateful allocator, that does not propagate_on_swap, then whether two objects of this type can be swapped with well defined behavior is a run-time property (the allocators compare equal) rather than a simple compile-time property that can be deduced from the type. Strictly speaking, any type where the nature of swap is a runtime property does not meet the swappable requirements of C++11, although typical sequences of such types are going to have elements that are all swappable with any other element in the sequence (using our other term of art for specifying requirements) as the common case is a container of elements who all share the same allocator.
The heart of the problem is that the swappable requirments demand that any two objects of the same type be swappable with each other, so if any two such objects would not be swappable with each other, then the whole type is never swappable. Many algorithms in clause 25 are specified in terms of swappable which is essentially an overspecification as all they actually need is that any element in the sequence is swappable with any other element in the sequence.
At this point Howard joins the discussion and points out that the intent of introducing the two swap-related terms was to support vector<bool>::reference types, and we are reading something into the wording that was never intended. Consuses is that regardless of the intent, that is what the words today say.
There is some support to see a paper reviewing the whole of clause 25 for this issue, and other select clauses as may be necessary.
There was some consideration to introducing a note into the front of clause 25 to indicate swappable requirements in the clause should be interpreted to allow such awkward types, but ultimately no real enthusiasm for introducing a swappable for clause 25 requirement term, especially if it confusingly had the same name as a term used with a subtly different meaning through the rest of the standard.
There was no enthusiasm for the alternate resolution of requiring containers with unequal allocators that do not propagate provide a well-defined swap behavior, as it is not believed to be possible without giving swap linear complexity for such values, and even then would require adding the constraint that the container element types are CopyConstructible.
Final conclusion: move to open pending a paper from a party with a strong interest in stateful allocators.
Sub-clause [swappable.requirements] defines two notions of swappability: a binary version defining when two objects are swappable with one another, and a unary notion defining whether an object is swappable (without qualification), with the latter definition requiring that the object satisfy the former with respect to all values of the same type.
Let T be a container type based on a non-propagating allocator whose instances do not necessarily compare equal. Then sub-clause [container.requirements.general] p7 implies that no object t of type T is swappable (by the unary definition). Throughout the standard it is the unary definition of "swappable" that is listed as a requirement (with the exceptions of [utility.swap] p4, [pairs.pair] p31, [tuple.swap] p2, [alg.swap] p2, and [alg.swap] p6, which use the binary definition). This renders many of the mutating sequence algorithms of sub-clause [alg.modifying.operations], for example, inapplicable to sequences of standard container types, even where every element of the sequence is swappable with every other. Note that this concern extends beyond standard containers to all future allocator-based types. Resolution proposal: I see two distinct straightforward solutions:I favor the latter solution, for reasons detailed in the following issue.
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-06-05 15:41:21 | admin | set | messages: + msg9217 |
2017-06-05 15:41:21 | admin | set | messages: + msg9216 |
2016-08-02 18:45:23 | admin | set | messages: + msg8337 |
2016-08-02 18:45:23 | admin | set | messages: + msg8336 |
2016-08-02 18:45:23 | admin | set | status: open -> lewg |
2016-03-08 22:51:25 | admin | set | messages: + msg8019 |
2012-10-25 12:46:45 | admin | set | status: new -> open |
2012-10-16 15:35:12 | admin | set | messages: + msg6172 |
2012-08-05 11:46:21 | admin | set | messages: + msg6091 |
2012-04-13 00:00:00 | admin | create |