294 {
295 constexpr ERRCODE DONT_EXCHANGE_DELETED("Can't exchange deleted elements of lists");
296
297 ELIST2_LINK *old_current;
298
299#ifndef NDEBUG
300 if (!list)
302 if (!other_it)
304 if (!(other_it->list))
306#endif
307
308
309
310
311 if ((list->
empty()) || (other_it->list->empty()) || (current == other_it->current)) {
312 return;
313 }
314
315
316
317 if (!current || !other_it->current) {
318 DONT_EXCHANGE_DELETED.error(
"ELIST2_ITERATOR.exchange",
ABORT);
319 }
320
321
322
323
324
325
326 if ((next == other_it->current) || (other_it->next == current)) {
327
328 if ((next == other_it->current) && (other_it->next == current)) {
329 prev = next = current;
330 other_it->prev = other_it->next = other_it->current;
331 } else {
332
333
334 if (other_it->next == current) {
335 other_it->prev->next = current;
336 other_it->current->next = next;
337 other_it->current->prev = current;
338 current->next = other_it->current;
339 current->prev = other_it->prev;
340 next->prev = other_it->current;
341
342 other_it->next = other_it->current;
343 prev = current;
344 } else {
345 prev->next = other_it->current;
346 current->next = other_it->next;
347 current->prev = other_it->current;
348 other_it->current->next = current;
349 other_it->current->prev = prev;
350 other_it->next->prev = current;
351
352 next = current;
353 other_it->prev = other_it->current;
354 }
355 }
356 } else {
357 prev->next = other_it->current;
358 current->next = other_it->next;
359 current->prev = other_it->prev;
360 next->prev = other_it->current;
361 other_it->prev->next = current;
362 other_it->current->next = next;
363 other_it->current->prev = prev;
364 other_it->next->prev = current;
365 }
366
367
368
369
370 if (list->last == current) {
371 list->last = other_it->current;
372 }
373 if (other_it->list->last == other_it->current) {
374 other_it->list->last = current;
375 }
376
377 if (current == cycle_pt) {
378 cycle_pt = other_it->cycle_pt;
379 }
380 if (other_it->current == other_it->cycle_pt) {
381 other_it->cycle_pt = cycle_pt;
382 }
383
384
385
386 old_current = current;
387 current = other_it->current;
388 other_it->current = old_current;
389}