STL
文章平均质量分 77
fantasyzzz
这个作者很懒,什么都没留下…
展开
-
STL LIST实现
struct _List_node_base { _List_node_base* _M_next; _List_node_base* _M_prev;}; //定义一个list的node的base class,包含一个指向前node和后node的pointer!template struct _List_node : public _List_node_base { _Tp _M_dat原创 2005-12-10 19:03:00 · 933 阅读 · 0 评论 -
STL vector 辅助函数
template inline bool operator==(const vector& __x, const vector& __y){ return __x.size() == __y.size() && equal(__x.begin(), __x.end(), __y.begin());}//判断相等template inline bool operator& __x,原创 2006-01-01 19:35:00 · 973 阅读 · 0 评论 -
STL vector 容器实现
template class vector : protected _Vector_base { // requirements: __STL_CLASS_REQUIRES(_Tp, _Assignable);private: typedef _Vector_base _Base;public: typedef _Tp value_type; typedef value_type* po原创 2005-12-31 18:30:00 · 2904 阅读 · 1 评论 -
C++ STL Algorithms
accumulatesum up a range of elementsadjacent_differencecompute the differences between adjacent elements in a rangeadjacent_findfinds two items that are adjacent to eachotherbinary_searchdetermine if原创 2006-01-03 15:28:00 · 1058 阅读 · 0 评论 -
STL vector
// The vector base class serves two purposes. First, its constructor// and destructor allocate (but dont initialize) storage. This makes// exception safety easier. Second, the base class encapsula原创 2005-12-29 21:10:00 · 943 阅读 · 0 评论 -
STL 适配器实现
// Adaptor function objects: pointers to member functions.// There are a total of 16 = 2^4 function objects in this family.// (1) Member functions taking no arguments vs member functions taking//原创 2005-12-28 13:28:00 · 1127 阅读 · 0 评论 -
STL FunctionObject实现 - sgi扩展
template struct _Identity : public unary_function { const _Tp& operator()(const _Tp& __x) const { return __x; }};template struct identity : public _Identity {};//验证模板参数是不是一个函数对象类型template struct _Se原创 2005-12-27 21:21:00 · 762 阅读 · 0 评论 -
STL FunctionObject实现 - 2
template class binder1st : public unary_function typename _Operation::result_type> {protected: _Operation op; typename _Operation::first_argument_type value;public: binde原创 2005-12-26 17:21:00 · 749 阅读 · 0 评论 -
STL FunctionObject实现
template struct unary_function { typedef _Arg argument_type; typedef _Result result_type;}; //只接受一个参数的函数所必须具备的参数集合模板template struct binary_function { typedef _Arg1 first_argument_type; typedef _Ar原创 2005-12-25 19:02:00 · 1021 阅读 · 0 评论 -
STL LIST实现 - 2
/* helper class for finding non-const version of a type. Need to have something to assign to etc. when testing constant iterators. */template struct _Mutable_trait { typedef _Tp _Type;};template st原创 2005-12-22 20:19:00 · 1072 阅读 · 0 评论 -
求两数和
小题大做!一般的写法template T add(T x, T y){return x+y;}此做法无法完成俩不同类型的操作换个方法:template P1 add(const P1& p1, const P2& p2){return p1+p2;}万一要返回P2呢,所以还的增加返回P2的版本:template P2 add(const P1& p1, const P2& p2){return p原创 2005-12-19 22:19:00 · 951 阅读 · 1 评论 -
C++ STL Vector
Container constructorscreate vectors and initialize them with some dataContainer operatorscompare, assign, and access elements of a vectorassignassign elements to a vectoratreturns an element at a spe原创 2006-01-06 15:26:00 · 1307 阅读 · 0 评论