298 {
299 constexpr ERRCODE DONT_EXCHANGE_DELETED("Can't exchange deleted elements of lists");
300
301
302
303
304 if ((list->
empty()) || (other_it->list->empty()) || (current == other_it->current)) {
305 return;
306 }
307
308
309
310 if (!current || !other_it->current) {
311 DONT_EXCHANGE_DELETED.error(
"CLIST_ITERATOR.exchange",
ABORT);
312 }
313
314
315
316
317
318
319 if ((next == other_it->current) || (other_it->next == current)) {
320
321 if ((next == other_it->current) && (other_it->next == current)) {
322 prev = next = current;
323 other_it->prev = other_it->next = other_it->current;
324 } else {
325
326
327 if (other_it->next == current) {
328 other_it->prev->next = current;
329 other_it->current->next = next;
330 current->next = other_it->current;
331 other_it->next = other_it->current;
332 prev = current;
333 } else {
334 prev->next = other_it->current;
335 current->next = other_it->next;
336 other_it->current->next = current;
337 next = current;
338 other_it->prev = other_it->current;
339 }
340 }
341 } else {
342 prev->next = other_it->current;
343 current->next = other_it->next;
344 other_it->prev->next = current;
345 other_it->current->next = next;
346 }
347
348
349
350
351 if (list->last == current) {
352 list->last = other_it->current;
353 }
354 if (other_it->list->last == other_it->current) {
355 other_it->list->last = current;
356 }
357
358 if (current == cycle_pt) {
359 cycle_pt = other_it->cycle_pt;
360 }
361 if (other_it->current == other_it->cycle_pt) {
362 other_it->cycle_pt = cycle_pt;
363 }
364
365
366
367 auto old_current = current;
368 current = other_it->current;
369 other_it->current = old_current;
370}