Jean-Marc Lasgouttes wrote:

> What I do not understand is why we use std::swap. Is that some clever
> C++ idiom? For example SwitchBetweenLayouts does
> 
> InsetText in;
> std::swap(in.paragraphs(), pars);
> 
> // layouts
> ParIterator end = par_iterator_end(in);
> for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
> [... etc ...]
> 
> std::swap(in.paragraphs(), pars);
> 
> So why don't we just remove these swap calls and be done with it?

As far as I understand this code we need an InsetText to create a
ParIterator. The std::swap calls should not copy any paragraph, but simply
exchange some internal pointers of the two paragraph lists (specialized
std::swap(std::vector, std::vector).
So the swap is explicitly there to avoid copying around a paragraph. Maybe
it does not work because of some weird overload and the generic std::swap()
is called which does copy its operands around?


Georg

Reply via email to