首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ STL中判断list为空,size()==零和empty()有什么区别

2014-01-13 
C++ STL中判断list为空,size()0和empty()有什么区别bool empty() const { return _M_node-_M_next _

C++ STL中判断list为空,size()==0和empty()有什么区别
bool empty() const { return _M_node->_M_next == _M_node; } size_type size() const { size_type __result = 0; distance(begin(), end(), __result); return __result; }

?可以看出empty直接检查标记节点,而size是通过求首尾迭代器的距离来获取元素个数的。

?

查看的源代码来自http://www.sgi.com/tech/stl/download.html

热点排行