Removing items from STL map without deletion? 
Author Message
 Removing items from STL map without deletion?

I may be completely confused here but I only see methods for
erasing(deleting) contained objects.  There seem to to be no way to remove
objects without deletion.  The "remove" algorigthm makes even less sense.

I have used Rogue Wave before and most of its collection classes provide a
get() method to pop the stored object out of the collection.  How can one
accomplish that with STL map or set

Zia Bhatti



Sat, 21 Apr 2001 03:00:00 GMT  
 Removing items from STL map without deletion?
    *iter  "gets" without deleting.
    erase(iter)  deletes without getting.

    The following should do what you want.....

    // WARNING untested code ahead
    template <typename T>
    T get(typename T::iterator iter)
    {
        T t = *iter;
        erase(iter);
        return (t);
    }

--
Truth,
   James [MVP]
http://www.NJTheater.Com       -and-
http://www.NJTheater.Com/JamesCurran

Quote:

>I may be completely confused here but I only see methods for
>erasing(deleting) contained objects.  There seem to to be no way to remove
>objects without deletion.  The "remove" algorigthm makes even less sense.

>I have used Rogue Wave before and most of its collection classes provide a
>get() method to pop the stored object out of the collection.  How can one
>accomplish that with STL map or set

>Zia Bhatti

begin 666 James M. Curran.vcf


M4DLZ.SLQ."!*;VAN(%-T+"!3=6ET92 R0CM";&]O;69I96QD.TY*.S W,# S
M+34Q-#D-"DQ!0D5,.U=/4DL[14Y#3T1)3D<]455/5$5$+5!224Y404),13HQ
M."!*;VAN(%-T+"!3=6ET92 R0CTP1#TP04)L;V]M9FEE;&0L($Y*(# W,# S
M+34Q-#D-"E523#IH='1P.B\O=W=W+DY*5&AE871E<BYC;VTO2F%M97-#=7)R
M86X-"E523#IH='1P.B\O=W=W+DY*5&AE871E<BYC;VT-"D5-04E,.U!2148[
M24Y415).150Z2F%M97-#=7)R86Y 0V]M<'5397)V92YC;VT-"E)%5CHQ.3DX

`
end


Sun, 22 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. STL's map<> item reorder

2. STL's map<> item reorder

3. STL - List Deletion

4. stl::map - can't map int to char *

5. STL vector<> allocation and deletion

6. MFC map or stl map

7. STL Newbie: STL maps

8. conditionally removing from map

9. Can't remove toolbar buttons without an unhandled exception

10. Can't remove toolbar buttons without an unhandled exception

11. Can't remove toolbar buttons without an unhandled exception

12. Remove duplicated items in an ArrayList

 

 
Powered by phpBB® Forum Software