1. // free the contents of the list; erase the list
  2.  
  3. inline void ListDelete (list <void *> *pList)
  4. {
  5. if (pList)
  6. {
  7. list <void *>::iterator iNext;
  8.  
  9. for (iNext = pList->begin (); iNext != pList->end (); ++iNext)
  10. free (*iNext);
  11.  
  12. pList->erase (pList->begin (), pList->end ());
  13. }
  14. }
  15.  
  16. // ----------------------------------------------------------------------
  17. // Delete the contents of a list; Erase the list
  18. //
  19. template <class T>
  20. void ListDelete (list <T> *pList)
  21. {
  22. if (pList)
  23. {
  24. list <T>::iterator iNext;
  25.  
  26. for (iNext = pList->begin (); iNext != pList->end (); )
  27. {
  28. // prefetch next position incase object destructor modifies list
  29. list <T>::iterator iThis = iNext++;
  30. delete *iThis;
  31. }
  32.  
  33. pList->erase (pList->begin (), pList->end ());
  34. }
  35. }
  36.  
  37. // ----------------------------------------------------------------------
  38. // Clear the contents of a list of pointers
  39. //
  40. template <class T>
  41. void ListClear (list <T> *pList)
  42. {
  43. if (pList)
  44. {
  45. list <T>::iterator iNext;
  46.  
  47. for (iNext = pList->begin (); iNext != pList->end (); ++iNext)
  48. *iNext = ;
  49. }
  50. }
  51.  
  52. // ----------------------------------------------------------------------
  53. // Delete the contents of a map; Erase the map
  54. //
  55. template <class Key, class Value, class Compare>
  56. void MapDelete (map <Key, Value, Compare> *pMap)
  57. {
  58. if (pMap)
  59. {
  60. map <Key, Value, Compare>::iterator iNext;
  61.  
  62. for (iNext = pMap->begin (); iNext != pMap->end (); ++iNext)
  63. delete (*iNext).second;
  64.  
  65. pMap->erase (pMap->begin (), pMap->end ());
  66. }
  67. }
  68.  
  69. // ----------------------------------------------------------------------
  70. // Clears the contents of a map of pointers
  71. // doesn't change the key values
  72. //
  73. template <class Key, class Value, class Compare>
  74. void MapClear (map <Key, Value, Compare> *pMap)
  75. {
  76. if (pMap)
  77. {
  78. map <Key, Value, Compare>::iterator iNext;
  79.  
  80. for (iNext = pMap->begin (); iNext != pMap->end (); ++iNext)
  81. (*iNext).second = ;
  82. }
  83. }
  84.  
  85. // ----------------------------------------------------------------------
  86. // Delete the contents of a vector; Erase the vector
  87. //
  88. template <class Value>
  89. void VectorDelete (vector <Value> *pvVector)
  90. {
  91. if (pvVector)
  92. {
  93. vector <Value>::iterator iNext;
  94.  
  95. for (iNext = pvVector->begin (); iNext != pvVector->end (); ++iNext)
  96. delete *iNext;
  97.  
  98. pvVector->erase (pvVector->begin (), pvVector->end ());
  99. }
  100. }
  101.  
  102. // ----------------------------------------------------------------------
  103. // Delete the contents of a set; Erase the set
  104. //
  105. template <class Key, class Compare>
  106. void SetDelete (set <Key, Compare> *pSet)
  107. {
  108. if (pSet)
  109. {
  110. set <Key, Compare>::iterator iNext;
  111.  
  112. for (iNext = pSet->begin (); iNext != pSet->end (); ++iNext)
  113. delete *iNext;
  114.  
  115. pSet->erase (pSet->begin (), pSet->end ());
  116. }
  117. }
  118.  
  119. // ----------------------------------------------------------------------
  120. // Clears the contents of a vector of pointers
  121. //
  122. template <class Value>
  123. void VectorClear (vector <Value> *pvVector)
  124. {
  125. if (pvVector)
  126. {
  127. vector <Value>::iterator iNext;
  128.  
  129. for (iNext = pvVector->begin (); iNext != pvVector->end (); ++iNext)
  130. *iNext = ;
  131. }
  132. }
  133.  
  134. // ----------------------------------------------------------------------
  135.  
  136. template <class T>
  137. class less_ptr : public binary_function<T, T, bool>
  138. {
  139. public:
  140. OS_STRUCT_CONSTRUCT (less_ptr)
  141.  
  142. bool operator () (const T& x_, const T& y_) const
  143. {
  144. return * x_ < * y_;
  145. }
  146. };
  147.  
  148. // ----------------------------------------------------------------------
  149.  
  150. template <class T>
  151. class unary_predicate : public unary_function<T,bool>
  152. {
  153. public:
  154.  
  155. unary_predicate(){}
  156. virtual bool operator () ( T argument )
  157. {
  158. return false;
  159. }
  160. };

C++删除容器数据的更多相关文章

  1. docker 12 docker容器数据卷

    数据卷概念 ♣我们知道,当我们把一个运行中的容器关闭后,容器里的数据就没有了(如果你做了docker commit操作,数据会保留到新的镜像里面).所以我们就需要用容器数据卷把容器数据进行持久化储存. ...

  2. Docker容器数据卷

    ⒈Docker容器中数据如何持久化? ①通过commit命令使容器反向为镜像 ②以容器数据卷的方式将数据抽离 ⒉容器数据卷的作用? ①容器数据的持久化 ②容器间继承.共享数据 ⒊能干嘛? 卷就是目录或 ...

  3. docker之容器数据持久化

    1.挂载本地目录为容器的数据存放目录 [root@node03 ~]# docker run -itd --name web01 -v /container_data/web:/data ubuntu ...

  4. Docker自学纪实(三)Docker容器数据持久化

    谈起数据卷 我一直觉得是个枯燥无聊的话题 但是通过今天的实操和阅读 我发现其实并不是 其实就像走夜路 没有光明,第一次都是恐惧 但是如果走的次数多了 或者静下心来去克制恐惧 也许就会驾轻就熟或者等到黎 ...

  5. Docker容器与容器数据

    Docker容器与容器数据 image 与container 镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的 类 和 实例 一样,镜像是静态的定义,容器是镜像运行时的 ...

  6. Docker容器数据卷(七)

    Docker致力于: 将运用与运行的环境打包形成容器运行 ,运行可以伴随着容器,但是我们对数据的要求希望是持久化的 容器之间希望有可能共享数据 Docker容器产生的数据,如果不通过docker co ...

  7. docker系列之六容器数据卷

    docker之容器数据卷 一.容器数据卷 docker容器运行的时候,会产生一系列的文件,那么我们希望容器产生的数据能提供给其他的容器使用,也就是说怎么实现容器间的数据的共享呢?这就需要用到我们所提到 ...

  8. 5、docker容器数据卷: -v添加共享传递容器数据卷

    1.是什么 1.docker理念 先来看看Docker的理念:*  将运用与运行的环境打包形成容器运行 ,运行可以伴随着容器,但是我们对数据的要求希望是持久化的*  容器之间希望有可能共享数据 2.保 ...

  9. Docker 容器数据卷(Data Volume)与数据管理

    卷(Volume)是容器中的一个数据挂载点,卷可以绕过联合文件系统,从而为Docker 提供持久数据,所提供的数据还可以在宿主机-容器或多个容器之间共享.通过卷,我们可以可以使修改数据直接生效,而不必 ...

随机推荐

  1. c# AddMonths,你了解吗?

    AddMonths:找到对应月的day,如果没有则取最后一个day var d1 = new DateTime(2017, 6, 30); var d2 = d1.AddMonths(-1);//20 ...

  2. Linux 命令之删除命令

    在Linux下删除文件用rm命令,具体用法如下: rm [选项] 文件 选项说明: -f -force 忽略不存在的文件,强制删除,无任何提示 -i --interactive 进行交互式地删除 -r ...

  3. php调用c#的dll(转)

    这几天,一直在做DES ecb模式的加解密,刚用.net实现了加解密,完了由于需要又要转型成PHP代码,费了九牛二虎之力单独用PHP没能实现,结构看到一篇php直接调用c#里生成的.dll文件的方法, ...

  4. rtmp和http方式在播放flv方面的各自优势和劣势

    下面是查的一点资料,比较一下用fms的rtmp和web的http播放flv的差别: 1. 区别 用HTTP方式:先通过IIS 将FLV下载到本地缓存,然后再通过NetConnection的本地连接来播 ...

  5. Golang client绑定本地IP和端口

    有时需要指定网络通信时本地使用的IP地址和端口号. 在Go语言中可通过定义 Dialer 中LocalAddr 成员实现. Dialer结构定义如下: // A Dialer contains opt ...

  6. Hadoop "Cannot create directory .Name node is in safe mode."解决方案

    转载自:http://www.waitig.com/hadoop-name-node-is-in-safe-mode.html 在使用Hadoop建立文件的时候,出现“Cannot create di ...

  7. hadoop 2.7.1安装和配置

    一.安装环境 硬件:虚拟机 操作系统:Centos 6.4 64位 IP:192.168.241.128主机名:admin安装用户:root 二.安装JDK 安装JDK1.7或者以上版本.这里安装jd ...

  8. openwrt挂载摄像头及视频保存

    一.编译选项的选择: -> Utilities ->usbutils (这个里面包含lsusb的命令,是查看你的摄像头型号的) -> Kernel modules -> I2C ...

  9. Hiero_FnNukeShotExporter的解析与修改

    研究对象:Hiero中的FnNukeShotExporter脚本 研究目的:修改FnNukeShotExporter使得可以将多个TrackItem导入到一个.nk中   FnNukeShotExpo ...

  10. 超细讲解Django打造大型企业官网

    本文为知了课堂黄勇老师讲的<超细讲解Django打造大型企业官网>的笔记. 第一章 Django预热 1.创建virtualenv虚拟环境 2.URL组成部分详解 3.Django介绍 4 ...