[Patch]New feature to all kind of stl container.vector::data_move() returns vector::data() that can be moved,just as unique_ptr::release() to unique_ptr::get()
Jonathan Wakely
jwakely.gcc@gmail.com
Thu Jan 8 13:36:00 GMT 2015
On 8 January 2015 at 13:31, 魅影圣域 <805600352@qq.com> wrote:
> Same as my original idea.
> my vector<T>::data_move() can be exactly in this function form
> T* data()&&;
That is a poor interface, which can cause currently working code to leak memory.
extern "C" void some_function(const int*, size_t);
std::vector<int> get_values(size_t n);
...
some_function(get_values(5).data(), 5);
Today this works correctly. With your suggestion the call to data()
would release ownership of the memory and it would never be freed.
> And thanks to Marc Glisse for works on std::string.
> Since it's a real nead,anyone consider my idea acceptable to libstdc++?
Definitely not in your suggested form, no.
The function must return some RAII type, which would probably make it
incompatible with existing uses of data(), so it should have a
different name.
More information about the Libstdc++
mailing list