Boost logo

Boost Users :

Subject: Re: [Boost-users] how to release element from ptr_map?
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-07-28 11:41:04


archie14 skrev:
> I have an instance of ptr_map<int, classA>. I need to release an element from
> the map and use it somewhere else, making sure that it will not be deleted
> when the instance of ptr_map is deleted.
>
> I am successfully doing it with ptr_vectors, but can't get it right with
> ptr_map.
> What is the proper syntax of such call?
>
> I am doing it like in the code below, which does not compile.
>
> class classA {};
>
> typedef ptr_map<int, classA> ptrmaptype;
>
> ptrmaptype val;
> val.insert(1, new classA());
>
> ptrmaptype::mapped_type t = val.release (val.begin()); // I want "t" to be of
> classA* type

Does

   ptrmaptype::auto_type ptr = val.release(val.begin());

not work??

Then you can call ptr.release() to get the naked ptr.

HTH

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net