From: Bill Buklis (boostuser_at_[hidden])
Date: 2007-08-28 17:52:58


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 --