This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2261. Are containers required to use their 'pointer' type internally?

Section: 24.2 [container.requirements] Status: C++17 Submitter: Jonathan Wakely Opened: 2013-05-14 Last modified: 2017-07-30

Priority: 2

View all other issues in [container.requirements].

View all issues with C++17 status.

Discussion:

Is a container C only supposed to refer to allocated memory (blocks of contiguous storage, nodes, etc.) through objects of type C::pointer rather than C::value_type*?

I don't see anything explicitly requiring this, so a container could immediately convert the result of get_allocator().allocate(1) to a built-in pointer of type value_type* and only deal with the built-in pointer until it needs to deallocate it again, but that removes most of the benefit of allowing allocators to use custom pointer types.

[2014-06-12, Jonathan comments]

This issue is basically the same issue as LWG 1521, which agrees it's an issue, to be dealt with in the future, so I request that 2261 not be closed as a dup unless we reopen 1521.

[2016-08, Zhihao comments]

The pointer types are not exposed in the container interface, and we consider that the memory allocation constraints "all containers defined in this clause obtain memory using an allocator" already implies the reasonable expectation. We propose the fix as non-normative.

[2016-08 Chicago]

Tues PM: General agreement on direction, Alisdair and Billy to update wording

Fri AM: Moved to Tentatively Ready

Proposed resolution:

This wording is relative to N4606.

[Drafting notes: if people prefer this to be normative, strip the "Note" markups.]

Modify 24.2.2.1 [container.requirements.general]/8 as indicated:

Unless otherwise specified, all containers defined in this clause obtain memory using an allocator (see 16.4.4.6 [allocator.requirements]). [Note: In particular, containers and iterators do not store references to allocated elements other than through the allocator's pointer type, i.e., as objects of type P or pointer_traits<P>::template rebind<unspecified>, where P is allocator_traits<allocator_type>::pointer. — end note]