[ptr_container]Swap/reorder elements in ptr_vector
28 Aug
2007
28 Aug
'07
9:52 p.m.
What is the best or recommended way to swap or reorder elements in a ptr_vector? Naturally, I simply want to swap pointers and not copy any elements. Using swap with the "base" iterator works (see below), but it feels like I'm using an undocumented feature or something. Is there a preferred method? Or is this the best approach? typedef boost::ptr_vector<int> VEC; VEC v; v.push_back( new int(1) ); v.push_back( new int(2) ); VEC::iterator a = v.begin(); VEC::iterator b = v.begin() + 1; // Swap the two underlying pointers using the base iterator std::swap( *a.base(), *b.base() ); -- Bill --
6301
Age (days ago)
6301
Last active (days ago)
0 comments
1 participants
participants (1)
-
Bill Buklis