Title
a missing/impossible allocator requirement
Status
cd1
Section
[allocator.requirements]
Submitter
Martin Sebor

Created on 2000-11-02.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

[ CuraƧao: LWG double checked and believes volatile is correctly excluded from the PR. ]

Date: 2010-10-21.18:28:33

Rationale:

Two resolutions were originally proposed: one that partially specialized std::allocator for const types, and one that said an allocator's value type may not be const. The LWG chose the second. The first wouldn't be appropriate, because allocators are intended for use by containers, and const value types don't work in containers. Encouraging the use of allocators with const value types would only lead to unsafe code.

The original text for proposed resolution 2 was modified so that it also forbids volatile types and reference types.

Date: 2010-10-21.18:28:33

[ Redmond: previous proposed resolution was "any non-const, non-volatile, non-reference type". Got rid of the "non-volatile". ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the text in row 1, column 2 of table 32 in 20.1.5, p3 from

any type

to

any non-const, non-reference type

Date: 2000-11-02.00:00:00

I see that table 31 in 20.1.5, p3 allows T in std::allocator<T> to be of any type. But the synopsis in 20.4.1 calls for allocator<>::address() to be overloaded on reference and const_reference, which is ill-formed for all T = const U. In other words, this won't work:

template class std::allocator<const int>;

The obvious solution is to disallow specializations of allocators on const types. However, while containers' elements are required to be assignable (which rules out specializations on const T's), I think that allocators might perhaps be potentially useful for const values in other contexts. So if allocators are to allow const types a partial specialization of std::allocator<const T> would probably have to be provided.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2078
2010-10-21 18:28:33adminsetmessages: + msg2077
2010-10-21 18:28:33adminsetmessages: + msg2076
2010-10-21 18:28:33adminsetmessages: + msg2075
2000-11-02 00:00:00admincreate