Move list element to the end in STL

后端 未结 3 693
野性不改
野性不改 2020-12-06 08:58

I have already the list pointer of CDrawObject*

std::list elements;

How I can move some element to the end of list. I s

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 09:48

    Use the list method splice()

    void list::splice ( iterator position, list& x, iterator i );

    Move iterator i from list x into current list at position "position"

    Thus to move it to the end put

    x.splice( x.end(), x, iter );
    

    (they can both be the same list or different lists as long as the list from which the item is moved has the same type, both T and Allocator)

提交回复
热议问题