摘要: forward_list 源码学习//forward_list的迭代器是forward_iterator,因此在forward list中需要注意保存前面一个元素的iterator,方便插入和删除。auto posbefore=flist.before_begin();for(auto pos=flist.begin();pos!=flist.end();++pos,++posbefore)例如在remove_if的成员函数 ,删除的是当前元素的后一个元素。template <class _Tp, class _Alloc> template <class _Predicat 阅读全文
posted @ 2013-03-31 21:53 xuning2516 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 在stl中既有通用函数,又有相同成员函数主要表现在list中。以remove为例 list<int> coll; // insert elements from 6 to 1 and 1 to 6 for (int i=1; i<=6; ++i) { coll.push_front(i); coll.push_back(i); } // print all elements of the collection cout << "pre: "; copy (coll.cbegin(), coll.cend... 阅读全文
posted @ 2013-03-31 21:36 xuning2516 阅读(309) 评论(0) 推荐(0) 编辑
摘要: 本文来自http://www.cplusplus.com/reference/stl/Member mapThis is a comparison chart with the different member functions present on each of the different containers:Legend:C++98Available since C++98C++11New in C++11Sequence containersHeaders<array><vector><deque><forward_list>< 阅读全文
posted @ 2013-03-31 16:58 xuning2516 阅读(205) 评论(0) 推荐(0) 编辑
摘要: C++11中新增了forward_list,头文件是<forward_list>这个container是一个单向链表,在sgi stl中对应的是slist数据结构中数据项保存的是头节点,尾节点初始化为0,表示链表的end()。template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) > class slist : private _Slist_base<_Tp,_Alloc> { // requirements: __STL_CLASS_REQUIRES(_Tp, _Assignable 阅读全文
posted @ 2013-03-31 16:50 xuning2516 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 在sgi stl的实现版本中看到关于size member的实现。size_type size() const { size_type __result = 0; distance(begin(), end(), __result); return __result; }这里的distance是一个全局函数。对于random_access iterator 而言是两个迭代器相减,具有O(1)的复杂度,而对于其他类型的迭代器则是++first到last的形式,具有O(n)的复杂度。 Why islist<>::size()linear time?Thesize()member... 阅读全文
posted @ 2013-03-31 13:16 xuning2516 阅读(259) 评论(0) 推荐(0) 编辑