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

1312. vector::data no longer returns a raw pointer

Section: [] Status: C++11 Submitter: Alisdair Meredith Opened: 2010-02-07 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [].

View all issues with C++11 status.


The original intent of vector::data was to match array::data in providing a simple API with direct access to the contiguous buffer of elements that could be passed to a "classic" C API. At some point, the return type became the 'pointer' typedef, which is not derived from the allocator via allocator traits - it is no longer specified to precisely T *. The return type of this function should be corrected to no longer use the typedef.

[ 2010-02-10 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Proposed resolution:

24.3.11 [vector]

Update the class definition in p2:

// data access
pointerT * data();
const_pointerconst T * data() const; []

Adjust signatures:

pointerT * data();
const_pointerconst T * data() const;