【问题标题】:forward_list::splice_after( const_iterator pos, forward_list& other, const_iterator i ) functionalityforward_list::splice_after(const_iterator pos, forward_list& other, const_iterator i) 功能
【发布时间】:2012-11-29 03:22:42
【问题描述】:

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

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

(PS:没有前向列表标签?)

【问题讨论】:

  • 我已经修复了 cppreference.com 页面。

标签: c++ list c++11 splice forward-list


【解决方案1】:

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 中删除。这 如果 position == i 或 position == ++i,结果不变。指向 *i 的指针和引用继续 引用相同的元素,但作为 *this 的成员。 *i 的迭代器(包括 i 本身)继续 引用相同的元素,但现在作为 *this 的迭代器,而不是 x 的迭代器。

【讨论】:

猜你喜欢
  • 2020-12-22
  • 2012-02-05
  • 2020-05-26
  • 1970-01-01
  • 2012-09-30
  • 2021-02-20
  • 1970-01-01
  • 2020-04-21
  • 2020-07-18
相关资源
最近更新 更多