DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

boost 循环缓冲区

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. #include <boost/circular_buffer.hpp>  
  2.   
  3. int _tmain(int argc, _TCHAR* argv[])  
  4. {  
  5.   
  6.     boost::circular_buffer<int> cb(3);  
  7.   
  8.     // Insert some elements into the buffer.  
  9.     cb.push_back(1);  
  10.     cb.push_back(2);  
  11.     cb.push_back(3);  
  12.   
  13.     int a = cb[0];  // a == 1  
  14.     int b = cb[1];  // b == 2  
  15.     int c = cb[2];  // c == 3  
  16.   
  17.     // The buffer is full now, pushing subsequent  
  18.     // elements will overwrite the front-most elements.  
  19.   
  20.     cb.push_back(4);  // Overwrite 1 with 4.  
  21.     cb.push_back(5);  // Overwrite 2 with 5.  
  22.   
  23.     // The buffer now contains 3, 4 and 5.  
  24.   
  25.     a = cb[0];  // a == 3  
  26.     b = cb[1];  // b == 4  
  27.     c = cb[2];  // c == 5  
  28.   
  29.     // Elements can be popped from either the front or the back.  
  30.   
  31.     cb.pop_back();  // 5 is removed.  
  32.     cb.pop_front(); // 3 is removed.  
  33.   
  34.     int d = cb[0];  // d == 4  
  35.   
  36.     return 0;  
  37. }  
posted on   DoubleLi  阅读(2222)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示