C++ std::list 和 std::forward_list 的差别及其成员函数差异对比
主要差别:
list 是双向链表,forward_list 是双向链表。
成员函数差异:
函数名 | list | forward_list |
back() | has | no |
size() | has | no |
insert() | has | no |
emplace() | has | no |
erase() | has | no |
push_back() | has | no |
emplace_back() | has | no |
splice() | has | no |
before_begin() | no | has |
cbefore_begin() | no | has |
insert_after() | no | has |
emplace_after() | no | has |
erase_after() | no | has |
splice_after() | no | has |
* forward_list 中设计的一系列 xxx_after() 的原因:
其中的元素仅知道后面的元素,不知道前面的元素。(单向链表的特性)所以类似于 insert 这样的操作,需要指定前一个元素的迭代器,然后执行插入,才可以把整个链表连接起来。
https://www.cnblogs.com/wuchanming/p/3915567.html
测试代码:
#include <iostream>
#include <string>
#include <list>
#include <forward_list> using namespace std; int main()
{ list<int> lis5 = {1,2,3};
forward_list<int> flis5 = { 1,2,3 }; ////////////////////////////////////////////////////////////////////////// lis5.insert(lis5.begin(), 44); // 44 1 2 3, 相当于 “insert_before”,不过并没有这个函数。
flis5.insert_after(flis5.begin(), 44); // 1 44 2 3 }
C++ std::list 和 std::forward_list 的差别及其成员函数差异对比的更多相关文章
- c++11特性与cocos2d-x 3.0之std::bind与std::function
昨天同事让帮忙写一小功能,才发现cocos2d-x 3.0 和 cocos2d-x 3.0rc0 差别还是相当大的. 发现Label这一个控件,3.0就比rc0版本多了一个创建函数,更为关键的是3.0 ...
- c++ 如何获取多线程的返回值?(std::thread ,std::async)
//简单的 c++11 线程,简单方便,成员函数随便调用,非成员函数也一样,如需要获取返回时,请自行使用条件变量 std::thread run([&](){ //执行一些耗时的操作 retu ...
- C++ std::unordered_map使用std::string和char *作key对比
最近在给自己的服务器框架加上统计信息,其中一项就是统计创建的对象数,以及当前还存在的对象数,那么自然以对象名字作key.但写着写着,忽然纠结是用std::string还是const char *作ke ...
- 使用std::map和std::list存放数据,消耗内存比实际数据大得多
使用std::map和std::list存放数据,消耗内存比实际数据大得多 场景:项目中需要存储一个结构,如下程序段中TEST_DATA_STRU,结构占24B.但是使用代码中的std::list&l ...
- STL的std::find和std::find_if
std::find是用来查找容器元素算法,但是它只能查找容器元素为基本数据类型,如果想要查找类类型,应该使用find_if. 小例子: #include "stdafx.h" #i ...
- std::unique_lock<std::mutex> or std::lock_guard<std::mutex> C++11 区别
http://stackoverflow.com/questions/20516773/stdunique-lockstdmutex-or-stdlock-guardstdmutex The diff ...
- C++11之std::function和std::bind
std::function是可调用对象的包装器,它最重要的功能是实现延时调用: #include "stdafx.h" #include<iostream>// std ...
- 解决程序出现“terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)”的问题
最近跑程序时出现了这么一个问题: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_al ...
- 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)'
error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Tra ...
随机推荐
- GitHub Actions 完成CI CD
在之前我的部署.版本控制.CI.CD都是在Jenkins 下来完成的 在前几天看到github上的一个新玩具actions,简直惊为天人 它能在你的仓库触发事件(Push,Pull,issue,... ...
- visual studio code开发代码片段扩展插件
背景 visual studio code编辑器强大在于可以自己扩展插件,不仅可以去插件市场下载,也可以按照官方的API很方便的制作适合自己的插件: 自己最近在开发一个手机端网站项目,基于vant项目 ...
- pipelinedb学习笔记 - 1. Continuous Views (连续视图)
Continuous Views 一.Continuous Views 英文直译过来叫连续视图, 在pipelindb中是被定义为专门用来展示 Stream中数据用的.例如:Stream中有一些用户信 ...
- docker-compose编排参数详解
一.前言 Compose是一个用于定义和运行多容器Docker应用程序的工具.使用Compose,您可以使用YAML文件来配置应用程序的服务.然后,使用单个命令,您可以从配置中创建并启动所有服务. C ...
- Nginx 常用配置方式说明
原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/7619763f-1 ...
- C#线程学习笔记七:Task详细用法
一.Task类简介: Task类是在.NET Framework 4.0中提供的新功能,主要用于异步操作的控制.它比Thread和ThreadPool提供了更为强大的功能,并且更方便使用. Task和 ...
- ASP.NET CORE 使用Consul实现服务治理与健康检查(2)——源码篇
题外话 笔者有个习惯,就是在接触新的东西时,一定要先搞清楚新事物的基本概念和背景,对之有个相对全面的了解之后再开始进入实际的编码,这样做最主要的原因是尽量避免由于对新事物的认知误区导致更大的缺陷,Bu ...
- NPOI 获取单元格的值
1.日期格式的坑 var cell = row.GetCell(i);//获取某一个单元格 var value = ""; if (cell != null) { if (cell ...
- NGUI 源码分析- UIWidgetInspector
NGUI Version 3.9.0 //---------------------------------------------- // NGUI: Next-Gen UI kit // Copy ...
- Appium(六):元素定位
1. 元素定位 对于自动化测试来说,核心技能就是对象的定位了.不管是web页面上的按钮或输入框,还是移动app上的一个按钮或输入框,我们要想对其进行点击或输入操作,前提是要先找到这个对象. webdr ...