C++ Reference: Standard C++ Library reference: Containers: list: list: pop_front

C++官网参考链接:https://cplusplus.com/reference/list/list/pop_front/

公有成员函数
<list>
std::list::pop_front
void pop_front();
删除第一个元素
删除list容器中的第一个元素,有效地将其size减少1。
这会销毁被删除的元素。

形参 
没有形参。 

返回值
没有返回值。

用例
// list::pop_front
#include <iostream>
#include <list>

int main ()
{
  std::list<int> mylist;
  mylist.push_back (100);
  mylist.push_back (200);
  mylist.push_back (300);

  std::cout << "Popping out the elements in mylist:";
  while (!mylist.empty())
  {
    std::cout << ' ' << mylist.front();
    mylist.pop_front();
  }

  std::cout << "\nFinal size of mylist is " << mylist.size() << '\n';

  return 0;
}
输出:
Popping out the elements in mylist: 100 200 300
Final size of mylist is 0

复杂度
常量。

iterator的有效性
指向被函数删除的元素的iterator、指针和reference将失效。
所有其他iterator、指针和reference保持它们的有效性。

数据竞争
完成容器的修改。
修改了第一个元素。同时访问或修改其他元素是安全的。

异常安全
如果容器不为empty,则函数永远不会抛出异常(无抛出保证)。
否则,它将导致未定义的行为。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_40186813

你的能量无可限量。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值