1404. pointer_traits should have a size_type member

Section: 20.2.3 [pointer.traits] Status: C++11 Submitter: INCITS Opened: 2010-08-25 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [pointer.traits].

View all issues with C++11 status.

Discussion:

Addresses US-106

pointer_traits should have a size_type member for completeness.

Add typedef see below size_type; to the generic pointer_traits template and typedef size_t size_type; to pointer_traits<T*>. Use pointer_traits::size_type and pointer_traits::difference_type as the defaults for allocator_traits::size_type and allocator_traits::difference_type.

See Appendix 1 - Additional Details

[ Post-Rapperswil, Pablo provided wording: ]

The original ballot comment reads simply: "pointer_traits should have a size_type for completeness." The additional details reveal, however, that the desire for a size_type is actually driven by the needs of allocator_traits. The allocator_traits template should get its default difference_type from pointer_traits but if it did, it should get its size_type from the same source. Unfortunately, there is no obvious meaning for size_type in pointer_traits.

Alisdair suggested, however, that the natural relationship between difference_type and size_type can be expressed simply by the std::make_unsigned<T> metafunction. Using this metafunction, we can easily define size_type for allocator_traits without artificially adding size_type to pointer_traits.

Moved to Tentatively Ready after 6 positive votes on c++std-lib.

[ Adopted at 2010-11 Batavia ]

Proposed resolution:

In [allocator.requirements], Table 42, change two rows as follows:

X::size_type unsigned integral type a type that can represent the size of the largest object in the allocation model size_t make_unsigned<X::difference_type>::type
X::difference_type signed integral type a type that can represent the difference between any two pointers in the allocation model ptrdiff_t pointer_traits<X::pointer>::difference_type

In [allocator.traits.types], Change the definition of difference_type and size_type as follows:

typedef see below difference_type;

Type: Alloc::difference_type if such a type exists, else ptrdiff_t pointer_traits<pointer>::difference_type.

typedef see below size_type;

Type: Alloc::size_type if such a type exists, else size_t make_unsigned<difference_type>::type.