Boost logo

Boost :

Subject: Re: [boost] [shifted_ptr] Documentation
From: Phil Bouchard (philippe_at_[hidden])
Date: 2011-04-10 15:22:41


On 4/9/2011 1:27 PM, Phil Bouchard wrote:
> py->p_.reset( new shifted<A>() ); // heap allocation #4

In fact reset() should be an affectator:
#include <iostream>

#include <boost/shifted_ptr.hpp>
#include <boost/shifted_allocator.hpp>

using namespace std;
using namespace boost;

struct A
{
        shifted_ptr<A> p;
        
        ~A() { std::cout << __FUNCTION__ << std::endl; }
};

struct X
{
        std::vector< shifted_ptr<A>, shifted_allocator< shifted_ptr<A> > > v_;

        ~X() { std::cout << __FUNCTION__ << std::endl; }
};

struct Y
{
        shifted_ptr<A> p_;

        ~Y() { std::cout << __FUNCTION__ << std::endl; }
};

int main()
{
        shifted_ptr<X> px = new shifted<X>(); // heap allocation #1
        px->v_.reserve( 5 ); // heap allocation #2
        shifted_ptr<Y> py = new shifted<Y>(); // heap allocation #3
        py->p_ = new shifted<A>(); // heap allocation #4
        px->v_.push_back( py->p_ ); // no heap allocation #5
}

Outputs:
~Y
~A
~X

Thanks,
-Phil


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