Boost logo

Boost :

Subject: Re: [boost] [cpo-proposal] presentation of the idea
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-08-23 11:08:53


On 08/23/13 02:41, Thorsten Ottosen wrote:
> On 23-08-2013 04:54, Ben Pope wrote:
>
>> But how can you be sure an arbitrary non-POD object in the vector
>> doesn't hold a pointer to itself?
>>
>> Also, this problem has just been found in Folly fbvector:
>> https://github.com/facebook/folly/issues/35
>
> WE can't, hence we need to call copy/move constructors via the virtual
> functions.
>
> -Thorsten

The attached code show a non-POD object containing a raw pointer to
itself and an offset_ptr to itself. It also shows an in-place
construction of such a non-POD object in a "from" std::vector<char>.
Then a COPY CTOR of another "to" std::vector<char>. The printouts
(also attached) show that the raw_ptr has wrong value in the "to"
but the offset_ptr has the correct value.

AFAICT, this shows the offset_ptr would solve the problem of moving
the storage in case the storage needs to be resized.

Am I missing something?

-Larry





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk