深圳罗湖网站制作公司锡林浩特本地网站建设

bicheng/2026/1/21 9:31:55/文章来源:
深圳罗湖网站制作公司,锡林浩特本地网站建设,wordpress备份如何恢复,跨境电商开店大概流程std::forward_list是可以从任何位置快速插入和移除元素的容器#xff0c;不支持快速随机访问#xff0c;只支持正向迭代。 本文章的代码库#xff1a; https://gitee.com/gamestorm577/CppStd 成员函数 构造、析构和赋值 构造函数 可以用元素、元素列表、迭代器或者另…std::forward_list是可以从任何位置快速插入和移除元素的容器不支持快速随机访问只支持正向迭代。 本文章的代码库 https://gitee.com/gamestorm577/CppStd 成员函数 构造、析构和赋值 构造函数 可以用元素、元素列表、迭代器或者另一个forward_list来构造forward_list。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::vectorfloat vec(10, 1.2f);std::forward_listfloat f1(4, 3.2f); std::forward_listfloat f2(4); std::forward_listfloat f3(vec.begin(), vec.end()); std::forward_listfloat f4(f1); std::forward_listfloat tmp(f1); std::forward_listfloat f5(std::move(tmp)); std::forward_listfloat f6{1.f, 2.f, 3.f};print_func(f1); print_func(f2); print_func(f3); print_func(f4); print_func(f5); print_func(f6); 输出结果 3.2 3.2 3.2 3.2 0 0 0 0 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 3.2 3.2 3.2 3.2 3.2 3.2 3.2 3.2 1 2 3 析构函数 forward_list析构时会按照正向顺序依次删除元素。代码示例 struct MyStruct {MyStruct(int i): Index(i){}~MyStruct(){std::cout destruct, Index Index std::endl;}int Index 0; };std::forward_listMyStruct f; f.emplace_front(1); f.emplace_front(3); f.emplace_front(5); 输出结果 destruct, Index 5 destruct, Index 3 destruct, Index 1 赋值函数 可以用元素列表或者另一个forward_list赋值给forward_list。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listfloat tmp {1.1f, 2.1f, 3.1f}; std::forward_listfloat f1; std::forward_listfloat f2;f1 tmp; f2 {2.1f, 2.2f, 2.3f, 2.4f}; print_func(f1); print_func(f2); 输出结果 1.1 2.1 3.1 2.1 2.2 2.3 2.4 assign 将值赋值给forward_list可以是元素、元素列表或者迭代器。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::vectorfloat vec(10, 1.2f); std::forward_listfloat f;f.assign(5, 1.2); print_func(f); f.assign(vec.begin(), vec.end()); print_func(f); f.assign({1.1f, 2.1f, 3.1f}); print_func(f); 输出结果 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.1 2.1 3.1 元素访问 front 返回首个元素的引用。示例代码 std::forward_listfloat f {1.f, 2.f, 3.f}; f.front() 4.1f; std::cout f front is: f.front() std::endl; 输出结果 f front is: 4.1 迭代器 before_begin和cbefore_begin返回forward_list开头之前的迭代器begin和cbegin返回forward_list起始的迭代器end和cend返回forward_list末尾的迭代器。代码示例 std::forward_listfloat f {1.f, 2.f, 3.f}; for (auto iter f.begin(); iter ! f.end(); iter) {*iter 1.1f; }for (auto iter f.cbegin(); iter ! f.cend(); iter) {std::cout num is: *iter std::endl; } 输出结果 num is: 2.1 num is: 3.1 num is: 4.1 容量 empty 检查forward_list是否为空。代码示例 std::forward_listfloat f1; std::forward_listfloat f2 {1.f, 2.f, 3.f}; std::cout std::boolalpha; std::cout f1 empty: f1.empty() std::endl; std::cout f2 empty: f2.empty() std::endl; 输出结果 f1 empty: true f2 empty: false max_size 返回可以容纳的最大元素个数。代码示例 struct MyStruct {double num1;double num2;double num3;double num4; };std::forward_listfloat f1; std::forward_listdouble f2; std::forward_listMyStruct f3; std::cout f1 max size f1.max_size() std::endl; std::cout f2 max size f2.max_size() std::endl; std::cout f3 max size f3.max_size() std::endl; 输出结果 f1 max size 1152921504606846975 f2 max size 1152921504606846975 f3 max size 461168601842738790 修改器 clear 清除所有的元素。代码示例 std::forward_listfloat f(3, 1.f); std::cout std::boolalpha; std::cout f empty: f.empty() std::endl; f.clear(); std::cout f empty: f.empty() std::endl; 输出结果 f empty: false f empty: true insert_after 在指定位置后面插入元素。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::vectorfloat tmp {11.1f, 11.2f, 11.3f}; std::forward_listfloat f {1.1f}; auto pos f.insert_after(f.begin(), 2.1f); print_func(f); f.insert_after(pos, 3, 3.1f); print_func(f); pos f.insert_after(f.begin(), tmp.begin(), tmp.end()); print_func(f); f.insert_after(pos, {25.1f, 25.2f}); print_func(f); 输出结果 1.1 2.1 1.1 2.1 3.1 3.1 3.1 1.1 11.1 11.2 11.3 2.1 3.1 3.1 3.1 1.1 11.1 11.2 11.3 25.1 25.2 2.1 3.1 3.1 3.1 emplace_after 在指定位置后面构造一个元素。代码示例 struct MyStruct {MyStruct(float num1, int num2){std::cout construct num1 num2 std::endl;} };std::forward_listMyStruct f; f.emplace_after(f.before_begin(), 1.4f, 2); f.emplace_after(f.before_begin(), 3.2f, 5); 输出结果 construct 1.4 2 construct 3.2 5 erase_after 移除指定位置后面的元素或者移除某个范围内的元素。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listfloat f {1.5f, 2.5f, 3.5f, 4.5f, 5.5f}; f.erase_after(f.begin()); print_func(f); f.erase_after(f.begin(), std::next(f.begin(), 3)); print_func(f); 输出结果 1.5 3.5 4.5 5.5 1.5 5.5 push_front 在起始位置插入一个元素。代码示例 std::forward_listfloat f {1.1f, 2.1f}; std::cout f front is: f.front() std::endl; f.push_front(3.1f); std::cout f front is: f.front() std::endl; 输出结果 f front is: 1.1 f front is: 3.1 emplace_front 在起始位置构造一个元素。代码示例 struct MyStruct {MyStruct(float num1, int num2){std::cout construct num1 num2 std::endl;} };std::forward_listMyStruct f; f.emplace_front(2.1f, 5); f.emplace_front(2.5f, 3); 输出结果 construct 2.1 5 construct 2.5 3 pop_front 移除forward_list的首个元素。代码示例 std::forward_listfloat f {1.1f, 2.1f, 3.1f}; std::cout f front is: f.front() std::endl; f.pop_front(); std::cout f front is: f.front() std::endl; 输出结果 f front is: 1.1 f front is: 2.1 resize 重新设置元素的个数。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listfloat f {1.1f, 2.1f, 3.1f, 4.1f}; print_func(f); f.resize(2); print_func(f); 输出结果 1.1 2.1 3.1 4.1 1.1 2.1 swap 和另一个forward_list交换元素内容。代码示例 std::forward_listfloat f1 {1.1f, 2.1f, 3.1f}; std::forward_listfloat f2 {11.5f, 12.5f, 13.5f, 14.5f}; f1.swap(f2); std::cout f1 front is: f1.front() std::endl; std::cout f2 front is: f2.front() std::endl; 输出结果 f1 front is: 11.5 f2 front is: 1.1 操作 sort 对元素进行排序。代码示例 auto print_func [](const std::forward_listint list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listint f {5, 2, 18, 9}; print_func(f);f.sort(); print_func(f);f.sort([](int a, int b){return a b;}); print_func(f); 输出结果 5 2 18 9 2 5 9 18 18 9 5 2 merge 合并两个有序的列表。代码示例 auto print_func [](const std::forward_listint list) {for (auto i : list){std::cout i ;}std::cout std::endl; };{std::forward_listint f1 {1, 5, 7, 19};std::forward_listint f2 {2, 3, 14, 15};f1.merge(f2);print_func(f1); }{std::forward_listint f1 {1, 5, 7, 19};std::forward_listint f2 {2, 3, 14, 15};f1.merge(f2,[](int a, int b){return a b;});print_func(f1); } 输出结果 1 2 3 5 7 14 15 19 2 3 14 15 1 5 7 19 splice_after 将另一个列表中的一些元素移动到this列表指定的位置。代码示例 auto print_func [](std::string tag, const std::forward_listfloat list) {std::cout tag;for (auto i : list){std::cout i ;}std::cout std::endl; };{std::forward_listfloat f1 {1.5f, 5.5f, 7.5f, 19.5f};std::forward_listfloat f2 {2.4f, 3.4f, 14.4f, 15.4f};f1.splice_after(f1.begin(), f2);print_func(f1 , f1);print_func(f2 , f2); }{std::forward_listfloat f1 {1.5f, 5.5f, 7.5f, 19.5f};std::forward_listfloat f2 {2.4f, 3.4f, 14.4f, 15.4f};f1.splice_after(std::next(f1.begin(), 2), f2, std::next(f2.begin(), 1));print_func(f1 , f1);print_func(f2 , f2); }{std::forward_listfloat f1 {1.5f, 5.5f, 7.5f, 19.5f};std::forward_listfloat f2 {2.4f, 3.4f, 14.4f, 15.4f};f1.splice_after(f1.begin(), f2, f2.begin(), std::next(f2.begin(), 2));print_func(f1 , f1);print_func(f2 , f2); } 输出结果 f1 1.5 2.4 3.4 14.4 15.4 5.5 7.5 19.5 f2 f1 1.5 5.5 7.5 14.4 19.5 f2 2.4 3.4 15.4 f1 1.5 3.4 5.5 7.5 19.5 f2 2.4 14.4 15.4 remove、remove_if remove移除等于指定值的元素。remove_if移除满足指定要求的元素。代码示例 auto print_func [](const std::forward_listint list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listint f {5, 9, 17, 27, 15, 5, 5}; print_func(f);f.remove(5); print_func(f);f.remove_if([](int n){return n 15;}); print_func(f); 输出结果 5 9 17 27 15 5 5 9 17 27 15 9 15 reverse 反转元素的顺序。代码示例 auto print_func [](const std::forward_listfloat list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listfloat f {1.1f, 3.1f, 19.1f, 7.1f}; print_func(f); f.reverse(); print_func(f); 输出结果 1.1 3.1 19.1 7.1 7.1 19.1 3.1 1.1 unique 删除连续的重复元素。代码示例 auto print_func [](const std::forward_listint list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listint f {1, 3, 3, 17, 7, 3, 17, 17, 19, 1, 3, 1}; print_func(f); f.unique(); print_func(f); 输出结果 1 3 3 17 7 3 17 17 19 1 3 1 1 3 17 7 3 17 19 1 3 1 非成员函数 比较运算符 operator,!,,,,用于比较两个forward_list。代码示例 std::forward_listint f1 {1, 2, 3, 4}; std::forward_listint f2 {1, 5}; std::cout std::boolalpha; std::cout f1 f2: (f1 f2) std::endl; std::cout f1 ! f2: (f1 ! f2) std::endl; std::cout f1 f2: (f1 f2) std::endl; std::cout f1 f2: (f1 f2) std::endl; std::cout f1 f2: (f1 f2) std::endl; std::cout f1 f2: (f1 f2) std::endl; 输出结果 f1 f2: false f1 ! f2: true f1 f2: true f1 f2: true f1 f2: false f1 f2: false swap 交换两个列表的元素内容。示例代码 std::forward_listfloat f1 {1.5f, 2.5f}; std::forward_listfloat f2 {17.1f, 15.1f, 27.1f}; std::swap(f1, f2); std::cout f1 front is: f1.front() std::endl; std::cout f2 front is: f2.front() std::endl; 输出结果 f1 front is: 17.1 f2 front is: 1.5 erase、erase_if erase删除等于指定值的元素erase_if删除满足条件的元素。代码示例 auto print_func [](const std::forward_listint list) {for (auto i : list){std::cout i ;}std::cout std::endl; };std::forward_listint f {5, 7, 17, 29, 7, 7, 35}; print_func(f);std::erase(f, 7); print_func(f);std::erase_if(f,[](int a){return a 17;}); print_func(f); 输出结果 5 7 17 29 7 7 35 5 17 29 35 5 17

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/88230.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在哪个网站注册域名好巩义网站建设案例课堂

结构体(简称struct)用于创建不同数据类型的成员集合,放入一个单一的变量中。虽然数组用于将相同数据类型的多个值存储在单一变量中,但结构体用于将不同数据类型的多个值存储在单一变量中。结构体对于将数据组合在一起以创建记录非…

珠海建设网站官网专业制作简历收费

一:什么是MVCC? 多版本并发控制,更好的方式去处理读-写冲突,就是为了查询一些正在被另一个事务更新的行,并且可以看到它们被更新之前的值,这样在做查询的时候就不用等待另一个事务释放锁。 二&#xff1a…

网站备案管理seo是怎么优化推广的

简介 雷风影视CMS是一款采用PHP基于THINKPHP3.2.3框架开发,适合各类视频、影视网站的影视内容管理程序,该CMS存在缺陷,可以通过 admin.php?s/Template/edit/path/*web*..*..*..*..*1.txt 的方式读取任意文件。 正文 1.进入靶场 2./admin…

郑州汉狮做网站网络公司辽宁网站建站系统平台

很简单,只需两步搞定: 一、打开工具,如图所示: 二、选择图片,进行拼接: 静待结果!

西安网站模板建站找个人合伙做网站

🎼个人主页:金灰 😎作者简介:一名简单的大一学生;易编橙终身成长社群的嘉宾.✨ 专注网络空间安全服务,期待与您的交流分享~ 感谢您的点赞、关注、评论、收藏、是对我最大的认可和支持!❤️ 🍊易编橙终身成长社群&#…

建立公司网站时什么是重要的青少年编程培训机构排名前十

string类 string不属于STL,早于STL出现 看文档 C非官网(建议用这个) C官网 文章目录 string类一.为什么学习string类?1.C语言中的字符串2. 两个面试题(暂不做讲解) 二.标准库中的string类1. string类(了解)2. string类的常用接口说明(注意下面我只讲解…

佛山网站建设 合优百度广告联盟入口

目录 一.for 1. 九九乘法表 2.求1到10奇数和 3.累计加到100 (1)方法一 (2)方法2 二.while 1.猜价格小游戏 2.累加到100的方法三 三.until循环 1.累加到100方法四 四.嵌套循环 五.循环语句中break、exit和continue 1…

什么是网站的访问流量百度推广全国代理商排名

在Go语言中,函数和方法是两个密切相关但又有所区别的概念。它们都用于封装可重用的代码块,但它们的应用场景和语法略有不同。 函数(Function) 函数是Go语言中的一等公民,它是一段独立的代码,用于执行特定任务。函数可以接受零个或多个参数,并可能返回零个或多个值。 …

太原网站维护医院网站设计怎么做

我们付出一些成本,时间的或者其他,最终总能收获一些什么。 如何使用 Esri 模板地理数据库 在学习之初,首先了解什么是Esri模板、如何使用Esri模板以及如何创建Esri模板 有两种类型的 Esri 模板:文件地理数据库 (.gd…

手机卡盟网站建设廊坊市建设网站

字符串问题&#xff0c;大家记得模板思路即可&#xff0c;一个类型的题目有很多种。 1. 字符串反转的问题 1.1 反转字符串 题目&#xff1a;LeetCode344: 思路 还是我们常见的双指针问题&#xff0c; left字符数组头部指针&#xff0c;right字符数组尾部指针。当left < r…

服饰的网站建设品牌策划公司名字大全

题目描述 题目分析 显而易见的重要事实 首先&#xff0c;需要明白一个很重要的事实&#xff1a; 所有的摆放方案数所有横着摆放且合理的方案数 这是因为&#xff0c;横着的确定之后&#xff0c;竖着的一定会被唯一确定&#xff0c;举一个例子&#xff1a; ------唯一确定-…

购买源码的网站Wordpress税表

一、跨站脚本攻击XSS? XSS就是通过在用户端注入恶意的可运行脚本&#xff0c;若服务端对用户的输入不进行处理&#xff0c;直接将用户的输入输出到浏览器&#xff0c;然后浏览器将会执行用户注入的脚本。 获取用户的输入&#xff0c;不用innerHtml,用innerText; 对用户的输入…

国外的ps网站网站宝搭建网站环境

数据挖掘作为从大量数据中提取有用信息和知识的过程&#xff0c;其结果的准确性和可靠性直接受到数据质量的影响。因此&#xff0c;数据预处理在数据挖掘中扮演着至关重要的角色。让我们探讨数据质量对数据挖掘结果的影响&#xff0c;并介绍常见的数据预处理方法以及它们如何提…

典型的电子商务网站有哪些天津百度推广优化排名

转载自 【开源组件】一份值得收藏的的 MySQL 规范 数据命名规范 所有数据库对象名称必须使用小写字母并用下划线分割。 所有数据库对象名称禁止使用 MySQL 保留关键字&#xff08;如果表名中包含关键字查询时&#xff0c;需要将其用单引号括起来&#xff09;。 数据库对象的…

成品网站和模板建站php之wordpress

目录 一、Arcgis 定义投影 1、定义投影 2、设置平移 二、投影变换 1、栅格数据的投影变换 2、矢量数据的投影变换

企业宣传网站系统建设方案宁波seo软件

本文主要来讲解6大标签&#xff0c;以便更好的MyBatis操作数据库&#xff01; <if>标签<trim>标签<where>标签<set>标签<foreach>标签<include>标签 前提需求&#xff1a; MyBatis是一个持久层框架&#xff0c;和Spring没有任何关系&…

做ppt模板的网站有哪些厦门安能建设公司网站

NextJs中如果使用Route Handlers来编写Restful API接口&#xff0c;可以使用winston来将日志存储到文件。 winston Winston是一个Node.js的日志记录库&#xff0c;它可以帮助开发人员记录应用程序中的重要日志信息并进行分析。Winston支持多种日志记录级别&#xff0c;包括调…

建站公司推广博爱网站建设

TIA博途Wincc_通过VBS脚本实现电机风扇或水泵旋转动画的具体方法 前面和大家介绍了通过在PLC中编程,结合HMI的图形IO域实现电机风扇或水泵旋转动画的具体方法,详细内容可参考以下链接: TIA博途Wincc中制作电机风扇或水泵旋转动画的具体方法示例 本次和大家分享通过VBS脚本实…

网站备案 拨测返利淘客网站源码

官方版本 现在能阅读电子教材的官方网站挺多的&#xff0c;例如 人民教育出版社-电子教材&#xff0c;还有 国家中小学智慧教育平台 &#xff0c;其他还有很多可在阅读的网站。由于平台的原因不能直接贴链接&#xff0c;大家可以通过搜索关键词找到网站。 如何下载 据我所知…

中国石化工程建设公司网站怎么做自己的充值网站

文章目录 1、什么是intern&#xff1f;2、经典例题解释例1例2例3 1、什么是intern&#xff1f; String::intern()是一个本地方法&#xff0c;它的作用是如果字符串常量池中已经包含一个等于此String对象的字符串&#xff0c;则返回代表池中这个字符串的String对象的引用&#…