POV-Ray : Newsgroups : povray.off-topic : Swapping vector elements : Re: Swapping vector elements Server Time
28 Jul 2024 14:19:50 EDT (-0400)
  Re: Swapping vector elements  
From: Warp
Date: 15 Jan 2014 14:16:33
Message: <52d6de91@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.