|
![](/i/fill.gif) |
Orchid Win7 v1 <voi### [at] dev null> wrote:
> OK, so we have a std::vector of pointers to task objects. How do we swap
> a pair of elements to change their order?
> Half the Internet claims this is std::swap(), the other half claim it's
> std::swap_iter(), and a few people claim it's something else again...
Well, it depends on whether you are dereferencing the vector elements
directly or whether you just have iterators to them.
If you have iterators pointing to the elements, then
std::iter_swap(iterator1, iterator2);
is just the same as
std::swap(*iterator1, *iterator2);
If you are indexing the vector directly, then just do a
std::swap(v[index1], v[index2]);
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |