4

我正在阅读对这个函数应该如何工作的不同解释。

cplusplus.com说这个函数应该“直接在 i 之后移动元素”。
然而cppreference.com说它拼接了元素 AT i。
MSvisual studio 同意 cplusplus.com。然而,实际上正确的行为是什么?我倾向于认为移动“在 i 之后”更合乎逻辑(& 不需要 N 时间来找到前一个节点)。

(PS:没有转发列表标签?)

4

1 回答 1

4

23.3.4.6

void splice_after(const_iterator position, forward_list& x, const_iterator i);
void splice_after(const_iterator position, forward_list&& x, const_iterator i);

效果:将 i 之后的元素插入到 *this 之后的位置,并将其从 x 中删除。如果位置 == i 或位置 == ++i,则结果不变。指向 *i 的指针和引用继续引用相同的元素,但作为 *this 的成员。*i 的迭代器(包括 i 本身)继续引用同一个元素,但现在表现为 *this 的迭代器,而不是 x 的迭代器。

于 2012-12-11T15:09:48.080 回答