侯捷stl源码剖析注释44 stl-source-sgi-iterator

合集下载

c++向量的用法

c++向量的用法

c++向量的用法C++中的向量(Vector)是一种动态数组,它能够自动调整大小以适应不同的元素数量。

向量属于标准模板库(Standard Template Library,STL)的一部分,它提供了许多方便的函数和操作符,用于方便地处理和操作元素。

下面将介绍向量的用法及相关参考内容。

1. 定义和初始化向量向量的定义需要包含<vector>头文件,并使用std命名空间。

我们可以使用以下方式来定义和初始化向量:```cpp#include <vector>#include <iostream>int main() {// 定义一个整数类型的向量std::vector<int> v1;// 定义一个浮点类型的向量,初始容量为10std::vector<float> v2(10);// 定义一个字符串类型的向量,并初始化为{"Hello", "World"}std::vector<std::string> v3{"Hello", "World"};// 定义一个空向量,并指定初始容量为5std::vector<char> v4(5, 'a');// 输出向量中的元素for (int i : v1) {std::cout << i << " ";}std::cout << std::endl;for (float f : v2) {std::cout << f << " ";}std::cout << std::endl;for (std::string str : v3) {std::cout << str << " ";}std::cout << std::endl;for (char c : v4) {std::cout << c << " ";}std::cout << std::endl;return 0;}```参考内容:- 《C++ Primer Plus》- 《C++标准库-深度剖析》,侯捷- 《C++标准库速查表》2. 向向量中添加元素向量提供了几个函数来添加元素:- push_back(value):在向量的末尾添加一个元素;- insert(iterator, value):在指定位置插入一个元素;- emplace(iterator, args...):在指定位置使用参数构造一个元素;- insert(iterator, n, value):在指定位置插入n个元素;- insert(iterator, first, last):在指定位置插入另一个区间内的元素。

STL源码 侯捷注释

STL源码 侯捷注释

STL源码侯捷注释《STL源码侯捷注释》是一本经典的程序员必备书籍,它为广大程序员提供了深入了解STL源码的机会。

本文将从以下几个方面进行分析和评价。

一、作者介绍侯捷是一位著名的程序员和作家,他曾获得多项国际和国内大奖,包括ACM国际程序设计竞赛金牌、IBM杰出软件奖、国家自然科学二等奖等。

他还是多本计算机书籍的作者,如《STL源码剖析》、《C++程序设计》等。

二、书籍概述《STL源码侯捷注释》是一本详细介绍STL源码的书籍,它对STL的各个组成部分进行了详细的解析和注释。

本书的主要特点包括:1.详细的注释:本书对STL源码的每个细节都进行了详细的解释和注释,使读者能够深入了解STL的实现原理。

2.清晰的结构:本书按照STL源码的结构进行组织,并提供了详细的目录和索引,方便读者查找和理解。

3.丰富的例子:本书提供了大量的例子,帮助读者更好地理解STL的使用方法和实现原理。

4.全面的覆盖:本书覆盖了STL的所有组成部分,包括容器、迭代器、算法、仿函数等。

三、书籍优点1.深入浅出:本书的注释和解释非常详细,但又不失深入浅出的风格,使读者能够轻松理解STL的实现原理。

2.丰富的例子:本书提供了大量的例子,使读者能够更好地理解STL的使用方法和实现原理。

3.清晰的结构:本书按照STL源码的结构进行组织,并提供了详细的目录和索引,方便读者查找和理解。

4.全面的覆盖:本书覆盖了STL的所有组成部分,包括容器、迭代器、算法、仿函数等。

四、书籍不足之处1.过于复杂:本书注释和解释的内容非常详细,但有时候可能会让读者感到过于复杂和深入,不太适合初学者。

2.缺少实战案例:本书提供了大量的例子,但是缺少实战案例,读者可能需要自己去实践。

五、适合读者群体《STL源码侯捷注释》适合以下读者群体:1.对STL源码有兴趣的程序员。

2.希望深入了解STL实现原理的程序员。

3.希望提高自己的STL编程能力的程序员。

4.想要更好地掌握C++语言和STL的程序员。

侯捷老师——STL源码剖析

侯捷老师——STL源码剖析

侯捷老师——STL源码剖析侯捷老师是国内知名的C++专家,他在C++领域有着很高的知名度和影响力。

他的《STL源码剖析》是一本非常经典的C++书籍,深入剖析了C++标准模板库(Standard Template Library,STL)的源代码,并详细解释了其设计思想和实现细节。

下面是对这本书的1200字以上的介绍。

《STL源码剖析》是一本写给C++程序员的经典著作,它由侯捷老师亲自编写,内容非常详尽和深入。

这本书主要介绍了C++标准模板库(STL)的源代码,并解析了其中的设计思想和实现细节。

通过阅读这本书,读者可以更好地理解STL的底层原理,提高自己的C++编程能力。

这本书共分为13个章节,每个章节都涉及了STL的不同组件和特性。

书中的内容既包括理论知识,也包括具体的代码实现。

侯捷老师用通俗易懂的语言和形象生动的例子,对STL的各个组件进行了详细介绍。

他从容器、迭代器、算法和函数对象等方面入手,逐步展开对STL的剖析。

每一章的结尾都有相关的练习题,读者可以通过做题来巩固所学知识。

在《STL源码剖析》中,侯捷老师对STL的源代码进行了深入分析,解释了其中的设计思想和实现原理。

他通过对容器的底层结构和操作进行剖析,揭示了STL的高效性和灵活性。

在对算法和函数对象的讲解中,他详细介绍了STL中的各种常用算法,并解释了它们的内部实现原理。

通过这种深入的分析,读者可以更好地理解STL的运作机制,并能够灵活运用STL进行程序设计。

除了对STL源代码的剖析,侯捷老师还对STL的使用和扩展进行了说明。

他介绍了STL的使用注意事项和常见问题,并给出了一些实用的编程技巧和优化建议。

此外,他还展示了如何扩展STL,给出了一些自定义容器和算法的示例。

这些内容对于想要深入学习和应用STL的读者来说是非常有价值的。

总的来说,侯捷老师的《STL源码剖析》是一本非常权威和深入的C++书籍,对于想要深入学习STL的C++程序员来说是一本必读之作。

面向对象的理论与C++实践清华课程设计

面向对象的理论与C++实践清华课程设计

面向对象的理论与C++实践清华课程设计一、课程介绍面向对象的理论与C++实践是清华大学计算机科学与技术系本科生专业选修课程,涵盖面向对象编程理论和C++编程实践两个方面,旨在帮助学生深入理解面向对象思想并用C++语言进行实现。

二、课程内容面向对象编程理论1.面向对象思想概述2.类与对象3.继承、多态与虚函数4.抽象类与纯虚函数5.STL库简介C++编程实践1.C++程序设计基础2.类与对象的实现3.继承、多态与虚函数的实现4.STL库的使用三、课程教材《C++ Primer》(第五版)(中文版),作者:Lippman, Lajoie, Moo,译者:侯捷。

四、课程参考资料1.《Effective C++》(中文版),作者:Scott Meyers,译者:侯杰。

2.《STL源码剖析》(中文版),作者:侯捷。

3.《深入浅出设计模式》(中文版),作者:程杰。

五、课程设计要求1.选题要求:要求选好一个项目,体现应用面向对象编程的思想。

2.设计方案包括:给出所设计类的类体及成员函数原型,试画出相应的类图,写出内部数据结构方案的描述,描述各类或各函数功能作用的注释。

3.程序要求:为了反映面向对象编程语言的特征,要使用C++语言进行编程,采用面向对象思想,必须使用类和对象来体现程序设计思想,要充分利用C++语言的特性和STL库进行程序开发。

六、课程设计流程第一阶段:选题第一次课程上老师将介绍课程设计大概内容,学生需要结合个人实际情况,选定一个初步的设计主题,初步选题可与老师讨论资讯。

相当于开题选题环节。

第二阶段:设计方案在确定题目后,需要自己独立完成课程设计方案。

设计方案要求如上述第五部分所说明。

相当于中期论文。

第三阶段:实现程序在建立好方案后,开始进行程序实现。

实现过程中出现问题,需及时向老师或助教请教解决,最终提交实现代码。

相当于结题报告。

七、课程评分标准1.选题:选题是否合理,是否具有一定难度性;2.设计方案:方案是否完善,方案中的类设计是否具有标准性;3.程序代码:代码是否规范,是否达到良好的代码质量,代码是否具有可扩充性、可移植性等软件工程方面的优良特征;4.报告:书面报告是否符合规范,语言表达、图表使用是否得当;5.程序演示:演示时是否条理清晰,是否表现出更高的带了解问题以及解决问题的能力。

stl的使用介绍的书籍

stl的使用介绍的书籍

stl的使用介绍的书籍STL(Standard Template Library,标准模板库)是C++编程语言的一个重要组成部分,它为C++程序员提供了一套丰富的数据结构和算法,极大地提升了开发效率和代码的可重用性。

本文将介绍几本关于STL使用的优秀书籍,帮助读者更好地掌握STL的应用。

1.《Effective STL》《Effective STL》是Scott Meyers写的一本经典著作,旨在向读者展示如何高效地使用STL。

书中通过丰富的示例和详细的讲解,介绍了STL中各个容器、算法和迭代器的使用方法和注意事项。

同时,书中还提供了许多实用的技巧和技巧,帮助读者写出高质量的STL代码。

2.《STL源码剖析》《STL源码剖析》是侯捷教授编著的一本经典教材,深入剖析了STL 的实现原理和内部机制。

这本书不仅讲解了STL中各个容器和算法的实现细节,还介绍了STL的设计思想和优化技巧。

通过阅读本书,读者可以更好地理解STL的底层实现,提升自己的编程能力。

3.《C++标准库》《C++标准库》是Nicolai M. Josuttis撰写的一本权威性书籍,全面介绍了C++标准库,包括STL在内的各个组件。

书中详细讲解了STL中容器、算法、迭代器、函数对象等的使用方法,并给出了大量的示例代码。

此外,书中还介绍了C++11、C++14和C++17中新添加的特性,使读者了解最新的C++标准库开发技术。

4.《STL教程与案例精解》《STL教程与案例精解》是郝斌编著的一本教材,通过大量的案例和实例,系统地讲解了STL的使用方法和应用技巧。

书中从容器、迭代器、算法等方面入手,深入浅出地介绍了STL的各个组成部分,并提供了丰富的练习题和案例分析,帮助读者巩固所学知识。

5.《STL源码剖析与应用》《STL源码剖析与应用》是李师贺编著的一本专门讲解STL源码和应用的书籍。

书中详细解析了STL的设计思想、实现原理和内部机制,帮助读者深入理解STL的底层实现。

STL源码剖析——deque的实现原理和使用方法详解

STL源码剖析——deque的实现原理和使用方法详解

STL源码剖析——deque的实现原理和使用方法详解deque(双端队列)是一种支持随机访问的数据结构,可以在队列两端进行插入和删除操作。

STL中的deque实现原理比较复杂,主要采用了分块连续存储的方式。

deque的底层数据结构由多个连续的块组成,每个块大小为固定的值,默认为512个元素。

每个块中的元素存储在一个连续的内存区域中,块与块之间通过一个指针链表连接起来。

deque的内部结构包含了一组指向块的指针,以及指向块内部元素的指针。

deque支持随机访问,可以通过指针直接访问指定位置的元素,时间复杂度为O(1)。

deque在插入和删除操作时需要考虑位置的前后情况。

若插入位置在deque的前半段,即与deque的起始位置的距离小于等于deque大小的一半,此时从deque的起始位置向前遍历,找到离插入位置最近的块,并在该块内完成插入操作。

同理,若插入位置在deque的后半段,则从deque的末尾位置开始向后遍历。

deque的插入和删除操作都需要涉及到内存的扩容和迁移,以保证数据的连续性。

当deque的容量不足时,会重新分配一块更大的内存空间,并将之前的数据迁移到新的内存空间中。

这一过程需要考虑到deque内部的指针和迭代器的更新。

deque的使用方法比较简单,可以通过#include <deque>来引入deque类的定义。

使用deque时需要注意以下几点:- 可以使用push_back(和push_front(函数向deque中插入元素,分别在队尾和队头插入。

- 使用pop_back(和pop_front(函数可以删除deque中的元素,分别删除队尾和队头的元素。

- 通过[]操作符可以随机访问deque中的元素。

- 使用size(函数可以获得deque中元素的个数。

- 使用clear(函数可以清空deque中的所有元素。

需要注意的是,deque由于采用了分块连续存储的方式,对于插入和删除操作的时间复杂度为O(1)。

侯捷stl源码剖析注释之11 sgi-std-bastring-cc

侯捷stl源码剖析注释之11 sgi-std-bastring-cc

<std\> 完整列表 The Annotated STL Sources 1G++ 2.91.57,cygnus\cygwin-b20\include\g++\std\ 完整列表// Member templates for the -*- C++ -*- string classes.// Copyright (C) 1994 Free Software Foundation// This file is part of the GNU ANSI C++ Library. This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation ; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this library; see the file COPYING. If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// As a special exception, if you link this library with files// compiled with a GNU compiler to produce an executable, this does not cause // the resulting executable to be covered by the GNU General Public License. // This exception does not however invalidate any other reasons why// the executable file might be covered by the GNU General Public License.// Written by Jason Merrill based upon the specification by Takanori Adachi // in ANSI X3J16/94-0013R2.extern "C++" {template <class charT, class traits, class Allocator>inline void * basic_string <charT, traits, Allocator>::Rep::operator new (size_t s, size_t extra){return Allocator::allocate(s + extra * sizeof (charT));}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::operator delete (void * ptr){Allocator::deallocate(ptr, sizeof(Rep) +reinterpret_cast<Rep *>(ptr)->res *sizeof (charT));}template <class charT, class traits, class Allocator>inline size_t basic_string <charT, traits, Allocator>::Rep::frob_size (size_t s){<std\> 完整列表 The Annotated STL Sources 2 size_t i = 16;while (i < s) i *= 2;return i;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::Rep *basic_string <charT, traits, Allocator>::Rep::create (size_t extra){extra = frob_size (extra + 1);Rep *p = new (extra) Rep;p->res = extra;p->ref = 1;p->selfish = false;return p;}template <class charT, class traits, class Allocator>charT * basic_string <charT, traits, Allocator>::Rep::clone (){Rep *p = Rep::create (len);p->copy (0, data (), len);p->len = len;return p->data ();}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::Rep::excess_slop (size_t s, size_t r){return 2 * (s <= 16 ? 16 : s) < r;}template <class charT, class traits, class Allocator>inline bool basic_string <charT, traits, Allocator>::check_realloc (basic_string::size_type s) const{s += sizeof (charT);rep ()->selfish = false;return (rep ()->ref > 1|| s > capacity ()|| Rep::excess_slop (s, capacity ()));}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::alloc (basic_string::size_type size, bool save)<std\> 完整列表 The Annotated STL Sources 3{if (! check_realloc (size))return;Rep *p = Rep::create (size);if (save){p->copy (0, data (), length ());p->len = length ();}elsep->len = 0;repup (p);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos1, size_type n1,const basic_string& str, size_type pos2, size_type n2){const size_t len2 = str.length ();if (pos1 == 0 && n1 >= length () && pos2 == 0 && n2 >= len2)return operator= (str);OUTOFRANGE (pos2 > len2);if (n2 > len2 - pos2)n2 = len2 - pos2;return replace (pos1, n1, str.data () + pos2, n2);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::copy (size_t pos, const charT *s, size_t n){if (n)traits::copy (data () + pos, s, n);}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::move (size_t pos, const charT *s, size_t n){if (n)<std\> 完整列表 The Annotated STL Sources 4 traits::move (data () + pos, s, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>&basic_string <charT, traits, Allocator>::replace (size_type pos, size_type n1, const charT* s, size_type n2){const size_type len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->copy (pos, s, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->copy (pos, s, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>inline void basic_string <charT, traits, Allocator>::Rep::set (size_t pos, const charT c, size_t n){traits::set (data () + pos, c, n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>& basic_string <charT, traits, Allocator>:: replace (size_type pos, size_type n1, size_type n2, charT c){const size_t len = length ();OUTOFRANGE (pos > len);if (n1 > len - pos)n1 = len - pos;LENGTHERROR (len - n1 > max_size () - n2);<std\> 完整列表 The Annotated STL Sources 5size_t newlen = len - n1 + n2;if (check_realloc (newlen)){Rep *p = Rep::create (newlen);p->copy (0, data (), pos);p->copy (pos + n2, data () + pos + n1, len - (pos + n1));p->set (pos, c, n2);repup (p);}else{rep ()->move (pos + n2, data () + pos + n1, len - (pos + n1));rep ()->set (pos, c, n2);}rep ()->len = newlen;return *this;}template <class charT, class traits, class Allocator>void basic_string <charT, traits, Allocator>::resize (size_type n, charT c){LENGTHERROR (n > max_size ());if (n > length ())append (n - length (), c);elseerase (n);}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::copy (charT* s, size_type n, size_type pos) const{OUTOFRANGE (pos > length ());if (n > length () - pos)n = length () - pos;traits::copy (s, data () + pos, n);return n;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::<std\> 完整列表 The Annotated STL Sources 6 find (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos + n <= length (); ++xpos)if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator>inline basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::_find (const charT* ptr, charT c, size_type xpos, size_type len){for (; xpos < len; ++xpos)if (traits::eq (ptr [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find (charT c, size_type pos) const{return _find (data (), c, pos, length ());}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (const charT* s, size_type pos, size_type n) const{if (n > length ())return npos;size_t xpos = length () - n;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], *s)&& traits::compare (data () + xpos, s, n) == 0)return xpos;return npos;}template <class charT, class traits, class Allocator><std\> 完整列表 The Annotated STL Sources 7basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::rfind (charT c, size_type pos) const{if (1 > length ())return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0; )if (traits::eq (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_of (const charT* s, size_type pos, size_type n) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) != npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (const charT* s, size_type pos, size_type n) const<std\> 完整列表 The Annotated STL Sources 8 {size_t xpos = pos;for (; xpos < length (); ++xpos)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_first_not_of (charT c, size_type pos) const{size_t xpos = pos;for (; xpos < length (); ++xpos)if (traits::ne (data () [xpos], c))return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (const charT* s, size_type pos, size_type n) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (_find (s, data () [xpos], 0, n) == npos)return xpos;return npos;}template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::find_last_not_of (charT c, size_type pos) const{if (length() == 0)return npos;size_t xpos = length () - 1;if (xpos > pos)xpos = pos;for (++xpos; xpos-- > 0;)if (traits::ne (data () [xpos], c))return xpos;<std\> 完整列表 The Annotated STL Sources 9return npos;}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const basic_string& str, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;if (rlen > str.length ())rlen = str.length ();int r = traits::compare (data () + pos, str.data (), rlen);if (r != 0)return r;if (rlen == n)return 0;return (length () - pos) - str.length ();}template <class charT, class traits, class Allocator>int basic_string <charT, traits, Allocator>::compare (const charT* s, size_type pos, size_type n) const{OUTOFRANGE (pos > length ());size_t rlen = length () - pos;if (rlen > n)rlen = n;int r = traits::compare (data () + pos, s, rlen);if (r != 0)return r;return (length () - pos) - n;}#include <iostream.h>template <class charT, class traits, class Allocator>istream &operator>> (istream &is, basic_string <charT, traits, Allocator> &s){int w = is.width (0);if (is.ipfx0 ()){register streambuf *sb = is.rdbuf ();s.resize (0);while (1)<std\> 完整列表 The Annotated STL Sources 10 {int ch = sb->sbumpc ();if (ch == EOF){is.setstate (ios::eofbit);break;}else if (traits::is_del (ch)){sb->sungetc ();break;}s += ch;if (--w == 1)break;}}is.isfx ();if (s.length () == 0)is.setstate (ios::failbit);return is;}template <class charT, class traits, class Allocator>ostream &operator<< (ostream &o, const basic_string <charT, traits, Allocator>& s) {return o.write (s.data (), s.length ());}template <class charT, class traits, class Allocator>istream&getline (istream &is, basic_string <charT, traits, Allocator>& s, charT delim) {if (is.ipfx1 ()){_IO_size_t count = 0;streambuf *sb = is.rdbuf ();s.resize (0);while (1){int ch = sb->sbumpc ();if (ch == EOF){is.setstate (count == 0? (ios::failbit|ios::eofbit)<std\> 完整列表 The Annotated STL Sources 11 : ios::eofbit);break;}++count;if (ch == delim)break;s += ch;if (s.length () == s.npos - 1){is.setstate (ios::failbit);break;}}}// We need to be friends with istream to do this.// is._gcount = count;is.isfx ();return is;}// static data member of class basic_string<>template <class charT, class traits, class Allocator>basic_string <charT, traits, Allocator>::Repbasic_string<charT, traits, Allocator>::nilRep = { 0, 0, 1, false };template <class charT, class traits, class Allocator>const basic_string <charT, traits, Allocator>::size_typebasic_string <charT, traits, Allocator>::npos ;} // extern "C++"。

stl源码剖析pdf

stl源码剖析pdf

STL源码剖析STL(Standard Template Library)是C++标准库中的一部分,它提供了一系列的模板类和函数,用于操作各种数据结构和算法,包括vector、list、map、set等容器,以及sort、find、c ount等算法。

STL的设计思想是将数据结构和算法分离,使得用户可以通过简单的组合和调用,完成复杂的数据处理任务。

STL的源码实现是一个非常庞大和复杂的工程,涉及到各种数据结构、算法、模板技术、编译器优化等方面的知识。

本文将从几个方面来剖析STL的源码实现,包括容器、迭代器、算法等方面。

一、容器STL提供了多种容器,包括vector、list、deque、map、set等。

这些容器都是模板类,可以存储不同类型的数据,并且支持各种常用的操作,比如插入、删除、查找、排序等。

以vector为例,其源码实现主要包括以下几个部分:1. 构造函数和析构函数:vector的构造函数可以接受多种参数,比如默认构造函数、指定大小的构造函数、拷贝构造函数等。

析构函数用于释放vector占用的内存。

2. 迭代器:vector提供了多种迭代器,包括普通迭代器、反向迭代器、常量迭代器等。

迭代器是STL的核心概念之一,它可以让用户通过类似指针的方式来访问容器中的元素。

3. 容量和大小:vector提供了多种方法来查询容器的大小和容量,比如size()、capacity()、e mpty()等。

4. 插入和删除:vector提供了多种方法来插入和删除元素,比如push_back()、pop_back()、insert()、erase()等。

5. 访问元素:vector提供了多种方法来访问容器中的元素,比如at()、front()、back()等。

二、迭代器迭代器是STL的核心概念之一,它可以让用户通过类似指针的方式来访问容器中的元素。

S TL提供了多种迭代器,包括普通迭代器、反向迭代器、常量迭代器等。

侯捷stl源码剖析注释45 stl-source-sgi-memory

侯捷stl源码剖析注释45 stl-source-sgi-memory

STL source 1 G++ 2.91.57,cygnus\cygwin-b20\include\g++\memory 完整列表/** Copyright (c) 1997* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Silicon Graphics makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty.**/#ifndef __SGI_STL_MEMORY#define __SGI_STL_MEMORY#include <stl_algobase.h>#include <stl_alloc.h>#include <stl_construct.h>#include <stl_tempbuf.h>#include <stl_uninitialized.h>#include <stl_raw_storage_iter.h>// Note: auto_ptr is commented out in this release because the details// of the interface are still being discussed by the C++ standardization// committee. It will be included once the iterface is finalized.#if 0#if defined(_MUTABLE_IS_KEYWORD) && defined(_EXPLICIT_IS_KEYWORD) && \defined(__STL_MEMBER_TEMPLATES)__STL_BEGIN_NAMESPACEtemplate <class X> class auto_ptr {private:X* ptr;mutable bool owns;public:typedef X element_type;explicit auto_ptr(X* p = 0) __STL_NOTHROW : ptr(p), owns(p) {}auto_ptr(const auto_ptr& a) __STL_NOTHROW : ptr(a.ptr), owns(a.owns) {a.owns = 0;}template <class T> auto_ptr(const auto_ptr<T>& a) __STL_NOTHROW: ptr(a.ptr), owns(a.owns) {a.owns = 0;2STL source }auto_ptr& operator=(const auto_ptr& a) __STL_NOTHROW {if (&a != this) {if (owns)delete ptr;owns = a.owns;ptr = a.ptr;a.owns = 0;}}template <class T> auto_ptr& operator=(const auto_ptr<T>& a) __STL_NOTHROW {if (&a != this) {if (owns)delete ptr;owns = a.owns;ptr = a.ptr;a.owns = 0;}}~auto_ptr() {if (owns)delete ptr;}X& operator*() const __STL_NOTHROW { return *ptr; }X* operator->() const __STL_NOTHROW { return ptr; }X* get() const __STL_NOTHROW { return ptr; }X* release const __STL_NOTHROW { owns = false; return ptr }};__STL_END_NAMESPACE#endif /* mutable && explicit && member templates */#endif /* 0 */#endif /* __SGI_STL_MEMORY */// Local Variables:// mode:C++// End:。

stl原理

stl原理

stl原理
STL原理是指标准模板库(Standard Template Library)的原理,它是一组C++模板类和函数的集合。

STL的目标是提供一套
通用的数据结构和算法,使得程序员能够更加高效地进行软件开发。

STL的核心思想是将数据结构和算法的实现与具体的数据类型无关,通过模板机制实现了数据结构和算法的高度通用性。

STL包括容器(containers)、算法(algorithms)和迭代器(iterators)三个主要组成部分。

容器是STL中最基本的概念,它相当于数据结构,提供了存
放数据的基本框架,包括vector、list、deque、set、map等等。

容器将数据的存储和访问进行了封装,提供了丰富的成员函数用于操作数据。

算法是STL中的核心,它提供了大量的基本算法,如排序、
查找、合并等等。

这些算法都是通过迭代器来操作容器中的元素,实现了算法和数据的解耦。

程序员可以直接使用这些算法,而无需关心具体的实现细节。

迭代器是STL中的另一个重要概念,它相当于指针,用于遍
历容器中的元素。

迭代器提供了类似指针的操作,如解引用、自增等,使得程序员可以通过迭代器来访问容器中的数据。

STL的原理可以总结为:通过使用模板机制,将数据结构和算法进行抽象和分离,使得程序员可以通过容器、算法和迭代器
来实现高效的数据处理。

STL的设计思想和实现方式为C++编程提供了很大的便利,使得开发人员可以更加专注于业务逻辑的实现。

vector源码1(参考STL源码--侯捷):源码

vector源码1(参考STL源码--侯捷):源码

vector源码1(参考STL源码--侯捷):源码vector源码1(参考STL源码--侯捷)vector概述Vector是动态空间,随着元素的加⼊,它的内部机制会⾃⾏扩充空间纳⼊新元素,vector的使⽤效率,关键在于其对⼤⼩的控制以及重新配置时的元素迁移效率。

Vector定义摘要template<class T,class Alloc=alloc>//alloc是SGI STL的空间配置器class vector{public:typedef T value_type;typedef value_type*pointer;typedef value_type*iterator;typedef value_type&reference;typedef size_t size_type;typedef ptrdiff_t difference_type;protected:typedef simple_alloc<value_type,Alloc>data_allocator;//simple_alloc是SGI STL的空间配置器iterator start;//表⽰⽬前使⽤空间的头iterator finish;//表⽰⽬前使⽤空间的尾iterator end_of_storage;//表⽰⽬前可⽤空间的尾void insert_aux(iterator position,const T&x);//插⼊元素,保护类型,对象不可调⽤void deallocate(){if(start)/*为vector再分配空间为其原始可容纳空间的⼀倍,deallocate()函数如下:*static void deallocate(T *p,size_t n){if(0!=n) Alloc::deallocate(p,n*sizeof(T));}*/data_allocator::deallocate(start,end_of_storage-start);}void fill_initialize(size_type n,const T&value){//⽤于vector初始赋值start=allocate_and_fill(n,value);finish=start+n;end_of_storage=finish;}public:iterator begin(){return start;}//头指针iterator end(){return finish;}//尾指针size_type size()const{return size_type(end()-begin());}//存储元素数量size_type capacity()const{return size_type(end_of_storage-begin());}//当前可容纳元素bool empty()const{return begin()==end();}//是否为空reference operator[](size_type n){return*(begin()+n);}//定位元素,返回第n+1个元素vector():start(0),finish(0),end_of_storage(0){}//初始化,如:vector<int> v;/*size_type是STL类中定义的类型属性,⽤以保存任意string和vector类对象的长度,以下都为初始化vector,如:vector<int> v(10,1)*/vector(size_type n,const T&value){fill_initialize(n,value);}vector(int n,const T&value){fill_initialize(n,value);}vector(long n,const T&value){fill_initialize(n,value);}//explit 防⽌隐式转换,此时初始化如:vector<int> v(10);explicit vector(size_type n){fill_initialize(n,T());}~vector(){/*全局函数,destory()有两个版本,第⼀个版本接收⼀个指针,准备将该指针指向的对象析构掉;第⼆个版本就是接收first和last两个迭代器(如下),将[first,last]下的对象析构掉。

STL源码剖析(一)

STL源码剖析(一)

STL源码剖析(⼀)SLT简介STL(Standard Template Library),即标准模板库,是⼀个⾼效的C++程序库。

包含了诸多在计算机科学领域⾥常⽤的基本数据结构和基本算法。

为⼴⼤C++程序员们提供了⼀个可扩展的应⽤框架,⾼度体现了软件的可复⽤性。

其核⼼思想就是泛化编程(generic programming),在这种思想⾥,⼤部分基本算法被抽象,被泛化,独⽴于与之对应的数据结构,⽤于以相同或相近的⽅式处理各种不同情形。

STL组件STL中包含了6⼤组件容器(Containers):包含各种基础的数据结构,如vector, list, deque, set, map等。

分配器(Allocators):负责空间配置与管理。

算法(Algorithms):各种常⽤的算法,如sort, search, copy, erase等等。

迭代器(Iterators):负责连接Containers与Algorithms。

适配器(Adapters):可以⽤来修饰Containers,Iterators和Functors接⼝的组件。

函数式(Functors):类似于函数,可以作为Algorithms的⼀种策略。

六⼤组件的关系Containers 通过 Allocators 取得数据存储空间,Algorithms 通过 Iterators 存取 Containers 内容,Functors 可以协助 Algorithms 完成不同的策略变,Adapters 可以修饰或套接Containers,Iterators和Functors。

容器结构与分类容器总体上分为三⼤类:Sequence Containers(序列容器): Arrary(⼤⼩固定,⽆法⾃动扩充), Vector(只可向后扩充, 两倍的扩展), Deque(可向前或向后扩充, 分段连续, stack和queue都是基于此), List(双向链表), Forwaed-List(单向链表)Associative Containers(关联容器):Set/Multiset, Map/Multimap(基本都⽤红⿊树来实现)Unordered Containers(⽆序容器): Unordered Set/Multiset, Unordered Map/Multimap(基本都是 HashTable Separate Chaining 实现)Array是⼀种固定⼤⼩的容器类型,在定义的时候就要声明⼤⼩和类型。

侯捷stl源码剖析注释之17 sgi-stl-33-function

侯捷stl源码剖析注释之17 sgi-stl-33-function

SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 1SGI STL 3.3 stl_function.h 完整列表/*** Copyright (c) 1994* Hewlett-Packard Company** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Hewlett-Packard Company makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty. *** Copyright (c) 1996-1998* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Silicon Graphics makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty. *//* NOTE: This is an internal header file, included by other STL headers. * You should not attempt to use it directly.*/#ifndef __SGI_STL_INTERNAL_FUNCTION_H#define __SGI_STL_INTERNAL_FUNCTION_H__STL_BEGIN_NAMESPACEtemplate <class _Arg, class _Result>struct unary_function {typedef _Arg argument_type;typedef _Result result_type;};template <class _Arg1, class _Arg2, class _Result>struct binary_function {typedef _Arg1 first_argument_type;typedef _Arg2 second_argument_type;typedef _Result result_type;};第1章 Classes 的語法和語意The Annotated STL Sources 2 template <class _Tp>struct plus : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } };template <class _Tp>struct minus : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } };template <class _Tp>struct multiplies : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } };template <class _Tp>struct divides : public binary_function<_Tp,_Tp,_Tp> {_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } };// identity_element (not part of the C++ standard).template <class _Tp> inline _Tp identity_element(plus<_Tp>) {return _Tp(0);}template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {return _Tp(1);}template <class _Tp>struct modulus : public binary_function<_Tp,_Tp,_Tp>{_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } };template <class _Tp>struct negate : public unary_function<_Tp,_Tp>{_Tp operator()(const _Tp& __x) const { return -__x; }};template <class _Tp>struct equal_to : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; } };template <class _Tp>struct not_equal_to : public binary_function<_Tp,_Tp,bool>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 3{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } };template <class _Tp>struct greater : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } };template <class _Tp>struct less : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } };template <class _Tp>struct greater_equal : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } };template <class _Tp>struct less_equal : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; } };template <class _Tp>struct logical_and : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } };template <class _Tp>struct logical_or : public binary_function<_Tp,_Tp,bool>{bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } };template <class _Tp>struct logical_not : public unary_function<_Tp,bool>{bool operator()(const _Tp& __x) const { return !__x; }};template <class _Predicate>class unary_negate: public unary_function<typename _Predicate::argument_type, bool> {第1章 Classes 的語法和語意The Annotated STL Sources 4 protected:_Predicate _M_pred;public:explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}bool operator()(const typename _Predicate::argument_type& __x) const { return !_M_pred(__x);}};template <class _Predicate>inline unary_negate<_Predicate>not1(const _Predicate& __pred){return unary_negate<_Predicate>(__pred);}template <class _Predicate>class binary_negate: public binary_function<typename _Predicate::first_argument_type,typename _Predicate::second_argument_type,bool> {protected:_Predicate _M_pred;public:explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}bool operator()(const typename _Predicate::first_argument_type& __x, const typename _Predicate::second_argument_type& __y) const {return !_M_pred(__x, __y);}};template <class _Predicate>inline binary_negate<_Predicate>not2(const _Predicate& __pred){return binary_negate<_Predicate>(__pred);}template <class _Operation>class binder1st: public unary_function<typename _Operation::second_argument_type,typename _Operation::result_type> {protected:_Operation op;typename _Operation::first_argument_type value;public:binder1st(const _Operation& __x,const typename _Operation::first_argument_type& __y)SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 5: op(__x), value(__y) {}typename _Operation::result_typeoperator()(const typename _Operation::second_argument_type& __x) const { return op(value, __x);}};template <class _Operation, class _Tp>inline binder1st<_Operation>bind1st(const _Operation& __fn, const _Tp& __x){typedef typename _Operation::first_argument_type _Arg1_type;return binder1st<_Operation>(__fn, _Arg1_type(__x));}template <class _Operation>class binder2nd: public unary_function<typename _Operation::first_argument_type,typename _Operation::result_type> {protected:_Operation op;typename _Operation::second_argument_type value;public:binder2nd(const _Operation& __x,const typename _Operation::second_argument_type& __y): op(__x), value(__y) {}typename _Operation::result_typeoperator()(const typename _Operation::first_argument_type& __x) const { return op(__x, value);}};template <class _Operation, class _Tp>inline binder2nd<_Operation>bind2nd(const _Operation& __fn, const _Tp& __x){typedef typename _Operation::second_argument_type _Arg2_type;return binder2nd<_Operation>(__fn, _Arg2_type(__x));}// unary_compose and binary_compose (extensions, not part of the standard).template <class _Operation1, class _Operation2>class unary_compose: public unary_function<typename _Operation2::argument_type,typename _Operation1::result_type>{protected:_Operation1 _M_fn1;第1章 Classes 的語法和語意The Annotated STL Sources 6 _Operation2 _M_fn2;public:unary_compose(const _Operation1& __x, const _Operation2& __y): _M_fn1(__x), _M_fn2(__y) {}typename _Operation1::result_typeoperator()(const typename _Operation2::argument_type& __x) const {return _M_fn1(_M_fn2(__x));}};template <class _Operation1, class _Operation2>inline unary_compose<_Operation1,_Operation2>compose1(const _Operation1& __fn1, const _Operation2& __fn2){return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);}template <class _Operation1, class _Operation2, class _Operation3>class binary_compose: public unary_function<typename _Operation2::argument_type,typename _Operation1::result_type> {protected:_Operation1 _M_fn1;_Operation2 _M_fn2;_Operation3 _M_fn3;public:binary_compose(const _Operation1& __x, const _Operation2& __y,const _Operation3& __z): _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }typename _Operation1::result_typeoperator()(const typename _Operation2::argument_type& __x) const {return _M_fn1(_M_fn2(__x), _M_fn3(__x));}};template <class _Operation1, class _Operation2, class _Operation3>inline binary_compose<_Operation1, _Operation2, _Operation3>compose2(const _Operation1& __fn1, const _Operation2& __fn2,const _Operation3& __fn3){return binary_compose<_Operation1,_Operation2,_Operation3>(__fn1, __fn2, __fn3);}template <class _Arg, class _Result>class pointer_to_unary_function : public unary_function<_Arg, _Result> { protected:_Result (*_M_ptr)(_Arg);public:SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 7pointer_to_unary_function() {}explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {} _Result operator()(_Arg __x) const { return _M_ptr(__x); }};template <class _Arg, class _Result>inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg)) {return pointer_to_unary_function<_Arg, _Result>(__x);}template <class _Arg1, class _Arg2, class _Result>class pointer_to_binary_function :public binary_function<_Arg1,_Arg2,_Result> {protected:_Result (*_M_ptr)(_Arg1, _Arg2);public:pointer_to_binary_function() {}explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)): _M_ptr(__x) {}_Result operator()(_Arg1 __x, _Arg2 __y) const {return _M_ptr(__x, __y);}};template <class _Arg1, class _Arg2, class _Result>inline pointer_to_binary_function<_Arg1,_Arg2,_Result>ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);}// identity is an extensions: it is not part of the standard.template <class _Tp>struct _Identity : public unary_function<_Tp,_Tp> {const _Tp& operator()(const _Tp& __x) const { return __x; }};template <class _Tp> struct identity : public _Identity<_Tp> {};// select1st and select2nd are extensions: they are not part of the standard. template <class _Pair>struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> { const typename _Pair::first_type& operator()(const _Pair& __x) const { return __x.first;}};template <class _Pair>struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>第1章 Classes 的語法和語意The Annotated STL Sources 8 {const typename _Pair::second_type& operator()(const _Pair& __x) const { return __x.second;}};template <class _Pair> struct select1st : public _Select1st<_Pair> {}; template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};// project1st and project2nd are extensions: they are not part of the standard template <class _Arg1, class _Arg2>struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {_Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; } };template <class _Arg1, class _Arg2>struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {_Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; } };template <class _Arg1, class _Arg2>struct project1st : public _Project1st<_Arg1, _Arg2> {};template <class _Arg1, class _Arg2>struct project2nd : public _Project2nd<_Arg1, _Arg2> {};// constant_void_fun, constant_unary_fun, and constant_binary_fun are // extensions: they are not part of the standard. (The same, of course, // is true of the helper functions constant0, constant1, and constant2.)template <class _Result>struct _Constant_void_fun {typedef _Result result_type;result_type _M_val;_Constant_void_fun(const result_type& __v) : _M_val(__v) {}const result_type& operator()() const { return _M_val; }};template <class _Result, class _Argument>struct _Constant_unary_fun {typedef _Argument argument_type;typedef _Result result_type;result_type _M_val;_Constant_unary_fun(const result_type& __v) : _M_val(__v) {}const result_type& operator()(const _Argument&) const { return _M_val; } };SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 9template <class _Result, class _Arg1, class _Arg2>struct _Constant_binary_fun {typedef _Arg1 first_argument_type;typedef _Arg2 second_argument_type;typedef _Result result_type;_Result _M_val;_Constant_binary_fun(const _Result& __v) : _M_val(__v) {}const result_type& operator()(const _Arg1&, const _Arg2&) const {return _M_val;}};template <class _Result>struct constant_void_fun : public _Constant_void_fun<_Result> {constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {} };template <class _Result,class _Argument __STL_DEPENDENT_DEFAULT_TMPL(_Result)>struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument> {constant_unary_fun(const _Result& __v): _Constant_unary_fun<_Result, _Argument>(__v) {}};template <class _Result,class _Arg1 __STL_DEPENDENT_DEFAULT_TMPL(_Result),class _Arg2 __STL_DEPENDENT_DEFAULT_TMPL(_Arg1)>struct constant_binary_fun: public _Constant_binary_fun<_Result, _Arg1, _Arg2>{constant_binary_fun(const _Result& __v): _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}};template <class _Result>inline constant_void_fun<_Result> constant0(const _Result& __val){return constant_void_fun<_Result>(__val);}template <class _Result>inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val) {return constant_unary_fun<_Result,_Result>(__val);}第1章 Classes 的語法和語意 The Annotated STL Sources 10template <class _Result>inline constant_binary_fun<_Result,_Result,_Result>constant2(const _Result& __val){return constant_binary_fun<_Result,_Result,_Result>(__val);}// subtractive_rng is an extension: it is not part of the standard. // Note: this code assumes that int is 32 bits.class subtractive_rng : public unary_function<unsigned int, unsigned int> { private:unsigned int _M_table[55];size_t _M_index1;size_t _M_index2;public:unsigned int operator()(unsigned int __limit) {_M_index1 = (_M_index1 + 1) % 55;_M_index2 = (_M_index2 + 1) % 55;_M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2]; return _M_table[_M_index1] % __limit;}void _M_initialize(unsigned int __seed){unsigned int __k = 1;_M_table[54] = __seed;size_t __i;for (__i = 0; __i < 54; __i++) {size_t __ii = (21 * (__i + 1) % 55) - 1;_M_table[__ii] = __k;__k = __seed - __k;__seed = _M_table[__ii];}for (int __loop = 0; __loop < 4; __loop++) {for (__i = 0; __i < 55; __i++)_M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55]; }_M_index1 = 0;_M_index2 = 31;}subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }subtractive_rng() { _M_initialize(161803398u); }};// Adaptor function objects: pointers to member functions.SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 11// There are a total of 16 = 2^4 function objects in this family.// (1) Member functions taking no arguments vs member functions taking // one argument.// (2) Call through pointer vs call through reference.// (3) Member function with void return type vs member function with// non-void return type.// (4) Const vs non-const member function.// Note that choice (3) is nothing more than a workaround: according// to the draft, compilers should handle void and non-void the same way. // This feature is not yet widely implemented, though. You can only use // member functions returning void if your compiler supports partial// specialization.// All of this complexity is in the function objects themselves. You can // ignore it by using the helper function mem_fun and mem_fun_ref,// which create whichever type of adaptor is appropriate.// (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,// but they are provided for backward compatibility.)template <class _Ret, class _Tp>class mem_fun_t : public unary_function<_Tp*,_Ret> {public:explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}_Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }private:_Ret (_Tp::*_M_f)();};template <class _Ret, class _Tp>class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {public:explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}_Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }private:_Ret (_Tp::*_M_f)() const;};template <class _Ret, class _Tp>class mem_fun_ref_t : public unary_function<_Tp,_Ret> {public:explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}_Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }private:_Ret (_Tp::*_M_f)();};第1章 Classes 的語法和語意The Annotated STL Sources 12 template <class _Ret, class _Tp>class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {public:explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {} _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }private:_Ret (_Tp::*_M_f)() const;};template <class _Ret, class _Tp, class _Arg>class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {public:explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}_Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg);};template <class _Ret, class _Tp, class _Arg>class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> { public:explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} _Ret operator()(const _Tp* __p, _Arg __x) const{ return (__p->*_M_f)(__x); }private:_Ret (_Tp::*_M_f)(_Arg) const;};template <class _Ret, class _Tp, class _Arg>class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {public:explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}_Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg);};template <class _Ret, class _Tp, class _Arg>class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {public:explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } private:_Ret (_Tp::*_M_f)(_Arg) const;};#ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _Tp>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 13class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {public:explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}void operator()(_Tp* __p) const { (__p->*_M_f)(); }private:void (_Tp::*_M_f)();};template <class _Tp>class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> { public:explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}void operator()(const _Tp* __p) const { (__p->*_M_f)(); }private:void (_Tp::*_M_f)() const;};template <class _Tp>class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {public:explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}void operator()(_Tp& __r) const { (__r.*_M_f)(); }private:void (_Tp::*_M_f)();};template <class _Tp>class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> { public:explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} void operator()(const _Tp& __r) const { (__r.*_M_f)(); }private:void (_Tp::*_M_f)() const;};template <class _Tp, class _Arg>class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> { public:explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }private:void (_Tp::*_M_f)(_Arg);};template <class _Tp, class _Arg>class const_mem_fun1_t<void, _Tp, _Arg>: public binary_function<const _Tp*,_Arg,void> {public:explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}第1章 Classes 的語法和語意The Annotated STL Sources 14 void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } private:void (_Tp::*_M_f)(_Arg) const;};template <class _Tp, class _Arg>class mem_fun1_ref_t<void, _Tp, _Arg>: public binary_function<_Tp,_Arg,void> {public:explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }private:void (_Tp::*_M_f)(_Arg);};template <class _Tp, class _Arg>class const_mem_fun1_ref_t<void, _Tp, _Arg>: public binary_function<_Tp,_Arg,void> {public:explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } private:void (_Tp::*_M_f)(_Arg) const;};#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */// Mem_fun adaptor helper functions. There are only two:// mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref// are provided for backward compatibility, but they are no longer// part of the C++ standard.)template <class _Ret, class _Tp>inline mem_fun_t<_Ret,_Tp> mem_fun (_Ret (_Tp::*__f)()){ return mem_fun_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline const_mem_fun_t<_Ret,_Tp> mem_fun (_Ret (_Tp::*__f)() const){ return const_mem_fun_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref (_Ret (_Tp::*__f)()){ return mem_fun_ref_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp>inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref (_Ret (_Tp::*__f)() const) { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }template <class _Ret, class _Tp, class _Arg>SGI STL 3.3 <stl_iterator.h> 完整列表 The Annotated STL Sources 15inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun (_Ret (_Tp::*__f)(_Arg)){ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun (_Ret (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref (_Ret (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>mem_fun_ref (_Ret (_Tp::*__f)(_Arg) const){ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg)){ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }template <class _Ret, class _Tp, class _Arg>inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const){ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }__STL_END_NAMESPACE#endif /* __SGI_STL_INTERNAL_FUNCTION_H */// Local Variables:// mode:C++// End:。

stl 常用算法

stl 常用算法

stl 常用算法摘要:1.STL 简介2.STL 常用算法分类3.排序算法4.查找算法5.图算法6.字符串匹配算法7.容器和迭代器正文:一、STL 简介STL(Standard Template Library,标准模板库)是C++编程语言中的一个重要组成部分,它包含了一系列通用、高效的模板类和函数,为程序员提供了对数据结构和算法的高级抽象。

STL 的目的是提高代码的可重用性、可移植性和效率。

二、STL 常用算法分类STL 中的算法主要可以分为以下几类:1.排序算法:用于对数据进行排序。

2.查找算法:用于在数据集合中查找特定元素。

3.图算法:用于处理图结构数据。

4.字符串匹配算法:用于在文本中查找子字符串。

5.容器和迭代器:用于存储和管理数据。

三、排序算法STL 中提供了一系列排序算法,如冒泡排序、选择排序、插入排序、快速排序、归并排序等。

这些算法可以根据数据类型和排序需求进行选择。

四、查找算法STL 中的查找算法包括顺序查找、二分查找、哈希查找等。

顺序查找适用于有序或无序数据,二分查找适用于有序数据,哈希查找则适用于快速查找。

五、图算法STL 中的图算法主要包括深度优先搜索(DFS)、广度优先搜索(BFS)、最短路径算法(如Dijkstra 算法、Floyd-Warshall 算法等)、最小生成树算法(如Prim 算法、Kruskal 算法等)。

这些算法可以处理各种图结构问题。

六、字符串匹配算法STL 中的字符串匹配算法主要有KMP 算法、Boyer-Moore 算法等。

这些算法可以在文本中高效地查找子字符串。

七、容器和迭代器STL 中的容器包括数组、链表、栈、队列、映射(如红黑树、哈希表等)、集合(如红黑树、哈希表等)等。

迭代器则是用于在容器中进行遍历的抽象概念,如输入迭代器、输出迭代器、前缀迭代器、后缀迭代器等。

总之,STL 中的常用算法为程序员提供了丰富的工具,可以帮助我们高效地实现各种数据结构和算法。

侯捷的c++课程内容

侯捷的c++课程内容

侯捷老师的C++课程内容非常丰富,涵盖了C++的基础知识、面向对象编程、STL标准库和泛型编程、设计模式、新标准C++11&14、内存管理机制等多个方面。

具体来说,侯捷老师的C++课程包括:
1.C++编程简介:介绍C++的基本语法和编程思想,包括变量、数据类型、运算符、
控制结构等。

2.面向对象编程:介绍面向对象的基本概念和C++中的类、对象、继承、多态等
概念,以及如何使用面向对象的方法进行程序设计。

3.STL标准库和泛型编程:介绍STL标准库中的容器、算法、迭代器等,以及泛
型编程的概念和实现方法。

4.设计模式:介绍常见的面向对象设计模式,如单例模式、工厂模式、观察者模
式等,以及如何使用设计模式来提高代码的可维护性和可重用性。

5.新标准C++11&14:介绍C++11和C++14的新特性,如智能指针、lambda
表达式、范围for循环等,以及如何使用这些新特性来提高代码的效率和可读性。

6.内存管理机制:介绍C++中的内存管理机制,包括动态内存分配、内存泄漏检
测、垃圾回收等,以及如何避免内存泄漏和优化内存使用。

此外,侯捷老师的C++课程还包括一些进阶内容,如多线程编程、网络编程等,以及一些实用的编程技巧和经验分享。

总的来说,侯捷老师的C++课程内容非常全面,从基础到进阶,从理论到实践,涵盖了C++编程的各个方面。

通过学习侯捷老师的C++课程,可以深入了解C++编程语言的特点和应用,提高编程能力和水平。

侯捷STL课程及源码剖析学习1

侯捷STL课程及源码剖析学习1

侯捷STL课程及源码剖析学习11.C++标准库和STL C++标准库以header files形式呈现:1. C++标准库的header files不带后缀名(.h),例如#include <vector>2. 新式C header files 不带后缀名.h,例如#include<cstdio>3. 旧式C header files (带有后缀名.h)仍然可⽤,例如#include <stdio.h>4. 新式headers内的组件封装于namespace “std”。

using namespace std;或者以 using std::cout;的形式5. 旧式headers 内的组件不封装于namespace "std" 在标准库中,标准模板库STL(Standard Template Library),占据了标准库70%,80%以上的内容。

C++ 标准库的范围⼤于STL的范围。

STL的核⼼思想是泛型编程(Generic Programming)。

重要资源:⽹站:书籍:The C++ standard Library second edition;STL 源码剖析2.STL 六⼤组件STL分为六⼤组件:容器(container):常⽤数据结构,⼤致分为两类,序列容器,如vector,list,deque,关联容器,如set,map。

在实现上,是类模板(class template)迭代器(iterator):⼀套访问容器的接⼝,⾏为类似于指针。

它为不同算法提供的相对统⼀的容器访问⽅式,使得设计算法时⽆需关注过多关注数据。

(“算法”指⼴义的算法,操作数据的逻辑代码都可认为是算法)算法(algorithm):提供⼀套常⽤的算法,如sort,search,copy,erase … 在实现上,可以认为是⼀种函数模板(function template)。

侯捷-C++ 内存管理与优化高级培训

侯捷-C++ 内存管理与优化高级培训

培训纲要
第 1 阶段:CRT (C Runtime) malloc 深度剖析 讓學員充份了解 Microsoft C++ 對 malloc 的作法(非常複雜精巧) ; 除學習其中技術, 也足以評估自行加上各種 allocators 是必要還是多 餘。 第 2 阶段:C++内存管理相关操作深入剖析,应用开发技巧、实践与模式 new expression vs. operator new delete expression vs. operator delete array new and array delete placement new about overhead examples for operator new/delete overloading 第 3 阶段: STL 程序库内存管理设施深入剖析,应用开发技巧、实践与模式 std::auto_ptr boost::shared_ptr How to inherit operator new/delete Introduction to std::allocator
第 3 页 共 3 页
培训简介
Memory management 一向是 C++ programmer 的痛点,主要因为 C++ 不提供 Garbage Collection。这是效能顾虑下的一种取舍。现实如此,我们必须追求在如此的现 实下如何又快又好地运用 memory,使符合速度和空间的最大利益。本课程在低阶上全 面介绍 C++ 提供的各种 memory 管理工具(各种 overloadable operators) ,在高阶上 深刻学习各大链接库(包括 STL, Loki, MFC, Boost)的 Pooled Allocation 的作法,并 提供它们的高度可移植版(侯捷改编) ,同时提供各种效率优化技巧实践、与模式。

侯捷stl源码剖析注释45 sgi-stl-tree

侯捷stl源码剖析注释45 sgi-stl-tree

The Annotated STL Sources
<stl_tree.h> 完整列表
3
base_ptr node; // 它用來與容器之間產生一個連結關係(make a reference)
// 以下其實可實作於 operator++ 內,因為再無他處會呼叫此函式了。
void increment()
base_ptr y = node->parent;
// 狀況(3) 找出父節點
while (node == y->left) {
// 當現行節點身為左子節點
node = y;
// 一直交替往上走,直到現行節點
y = y->parent;
// 不為左子節點
}
node = y;
// 此時之父節點即為答案
狀況3找出父節點當現行節點身為左子節點一直交替往上走直到現行節點不為左子節點此時之父節點即為答案lt
<stl_tree.h> 完整列表
1
G++ 2.91.57,cygnus\cygwin-b20\include\g++\stl_tree.h 完整列表 /* * * Copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Silicon Graphics makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * */

优秀IT书籍下载集锦100本

优秀IT书籍下载集锦100本

优秀IT书籍下载集锦100本1.vc++技术内幕第四版(潘爱民)ftp://210.32.157.56/课件/c++primer/vc++技术内幕IV(潘爱民).rar2.C++经典对话系列中文:/book/cvst_cn.chm3.MFC Windows 程序设计(第二版)英文版:/book/progmfc2.chm中文版:暂无,制作中...4.Effective C++中文版:/development/reference/effectiveCplus.zip5.More Effective C++中文版-zhc译/development/reference/MEC0410.zip6.More Effective C++中文版-候捷译/resources/MoreEffectiveC++(WQ).zip7.Essential C++中文版(全)-候捷译/resources/Essential%20C++中文版(全).rar8.深入浅出MFC 2/ehttp://218.30.21.125:8084/ebook/programme/mfc2e.zip9.代码大全中文版/docs/tecsubject/cc/CodeComplet110.zip11.C++经典对话系列中文:/book/cvst_cn.chm12.MFC Windows 程序设计(第二版)英文版:/book/progmfc2.chm中文版:暂无,制作中...13.数据结构C++ 语言描述(中文版)/manual/c_c015.zip14.Java编程思想中文版ftp://202.118.72.12/pub/doc-book/Java/Java编程思想.zip15.C++标准库英文版ftp://166.111.64.4/incoming/新文件夹/f/The%20C++%20Standard%20Library(with%20TOC).pdf16.Windows核心编程英文:/book/prgapps4.zip17.TCP-IP详解卷1:协议ftp://202.204.4.161/学习资料/TCPIP/TCP-IP详解卷1:协议.pdf18.TCP-IP详解卷2:实现ftp://202.204.4.161/学习资料/TCPIP/TCP-IP详解卷3:TCP事务协议,HTTP,NNTP.pdf19.TCP-IP详解卷3:TCP事务协议ftp://202.204.4.161/学习资料/TCPIP/TCP-IP详解卷2:实现.pdf20.实用算法的分析与程序设计ftp://202.204.8.10/[4]%20编程资源/[%20书籍资料%20]/[算法与数据结构]/实用算法的分析与程序设计.rar21.vc++技术内幕第四版(潘爱民)ftp://210.32.157.56/课件/c++primer/vc++技术内幕IV(潘爱民).rar22.C++ Primer英文版:/C/C++%20Primer.zip23.Effective C++中文版:/development/reference/effectiveCplus.zip24.More Effective C++中文版-zhc译/development/reference/MEC0410.zip25.More Effective C++中文版-候捷译/resources/MoreEffectiveC++(WQ).zip26.Essential C++中文版(全)-候捷译/resources/Essential%20C++中文版(全).rar27.Programming Windows程式开发设计指南-Petzoldi著余孟学译中文版:/resources/ProgrammingWindows_tw.chm英文版:/resources/Petzoldi.chm28.WinAsm32汇编教程-Iczelion/resources/winasm.chm29.Windows 95 程序设计指南-候捷译/resources/win95adg.zip30.Thinking in C++ 2nd Edition(C++编程思想)英文版:/resources/ThinkinginC++.zip中文版:/book/thinkc.zip31.人月神话-中文版/book/rysh.pdf32.The C++ Programming Language英文/C/The%20C++%20Programming%20Language.rar33.VC技术内幕第五版/downdata/book/programming/vc/book/vc++2/invcpp5.chm技术内幕/book/html/user/download.asp?id=1123+技术内幕/book/html/user/download.asp?id=95236.新编Windows API参考大全/nnsrc/down/WindowsAPIdq.rar37.The C programming Language // By Brian W. Kernighan and Dennis M. Ritchie下载地址:/book/The_C_programmin.chm38.C语言编程手册下载地址:/book/CL.chm39.Delphi 7高效数据库程序设计By 李维下载地址:/book/download.asp?id=1163&sort=540.Windows网络编程(第2版)By Anthony Jones,Jim Ohlund 清华大学出版社下载地址:英文版:/epubcn/readings/diannaotushu/500/download/1107/networ k_prog_for_win_2nd.zip41.Windows2000编程技术内幕By Mickey Williams 机械工业出版社下载地址:ftp:///Pub/Books/C&C++/VC/Windows2000编程技术内幕.rar42.数据仓库By W.H.Inmon 清华大学出版社下载地址1:/vvbksd/20011120/数据仓库.zip下载地址2: ftp:///Ebook/China-pub/chinapub_computerscience_multimedia/C omputerScience/%CA%FD%BE%DD%B2%D6%BF%E2/43.编码的奥秘By Charles Petzold 机械工业出版社下载地址:ftp:///Ebook/China-pub/chinapub_computerscience_multimedia/C omputerScience/%B1%E0%C2%EB%B5%C4%B0%C2%C3%D8/44.编译原理及实践By Louden, K.C 机械工业出版社下载地址:ftp:///Ebook/China-pub/chinapub_computerscience_multimedia/C omputerScience/%B1%E0%D2%EB%D4%AD%C0%ED%BC%B0%CA%B5%BC%F9/45.Inside C++ Object Model(深度探索C++对象模型)By Lippman 候捷译下载地址:/book/inside-the-cpp-object-model.pdf46.C++标准程序库By Josuttis下载地址1:/book/download.asp?id=1205&sort=5下载地址2: ftp:///Ebook/C_C++/The Cpp Standard Library.pdf47.STL源码剖析By 候捷下载地址:ftp:///Ebook/C_C++/STL源码剖析--侯捷.pdf48.C++批判(第三版) -看看C++的坏话!By I don't know下载地址:/book/CPPPP.pdf49.程序设计实践下载地址:ftp:///Ebook/China-pub/chinapub_computerscience_multimedia/ %B3%CC%D0%F2%C9%E8%BC%C6%CA%B5%BC%F9/50.c++沉思录By Andrew Koenig Barbara Moo 人民邮电出版社下载地址:/book/download.asp?id=1261&sort=551.C++Builder4技术内幕(这本书俺不知道好不好)By I don't Know下载地址:/book/download.asp?id=1254&sort=552.下面两本书一般大家硬盘里都有的吧,而且很老了,但是为了全面,就提上来吧(1)Windows 95 程式设计指南- 候捷下载地址:/win95-a-developers-guide.pdf(2)Windows 95 系统程式设计大奥秘- 候捷下载地址:/windows95-system-programming-secrets.pdf53. 中国大百科全书·数学下载地址:ftp:///Ebook/中国大百科全书/中国大百科全书·数学.pdf54、4.0M Bjarne Stroustrup - The C++ Programming Language/books/archive/The%20C++%20Programming%20Language.tar.gz55、1.0M Richard Stevens - TCP-IP Illustrated/books/archive/TCP-IP%20Illustrated.tar.gz56、4.5M Randall Hyde - Art Of Assembly/books/archive/Randall%20Hyde%20-%20Art%20Of%20Assembly. tar.gz57、2.1M M. Abrash - Zen of Graphics Programming/books/archive/M.%20Abrash%20-%20Zen%20of%20Graphics%2 0Programming.zip58、249k Kernighan and Ritche - The C Programming Language/books/archive/Kernighan%20and%20Ritchie%20-%20The%20C% 20Programming%20Language.zip59、3.3M Bruce Schneier - Applied Cryptography/books/archive/Bruce%20Schneier%20-%20Applied%20Cryptograp hy.zip60、PHP4_Grundlagen_und_Profiwissen/books/archive/lamp/PHP4_Grundlagen_und_Profiwissen.pdf61.《C++ Builder高级编程技术》/book/builder.zip62.《VC++ 6.0 TLR 模板库参考手册》/diannao/download/prog/c/mbkc.zip63.《BORLAND C++ BUILDER 实用培训教程》http://202.101.232.120/book/openfile.asp?id=223&filename=BC98_CB526.zip64.《Delphi高级开发指南》/s10899book/program/delphi/Delphi_gjkfzn_for3.rar65.《新编Windows API参考大全》ftp://book:book@/pro/delphi/新编Windows_API_参考大全.rar66.《Delphi深度历险-附书源码》/s10899book/program/delphi/Delphi_sdlx_code.rar67.《Delphi 7高效数据库程序设计》ftp://book:book@/pro/delphi/李维的新书《Delphi7高效数据库程序设计》.rar68.《Delphi7开发指南》ftp://book:book@/pro/delphi/delphi7开发指南.rar69.《Delphi6集成开发环境》ftp://book:book@/pro/delphi/Delphi6集成开发环境.rar70.《Delphi6数据库编程》ftp://book:book@/pro/delphi/Delphi6数据库编程.rar72.《Delphi5.xADO_MTS_COM+高级程序设计篇》ftp://book:book@/pro/delphi/Delphi5.xADO_MTS_COM+高级程序设计篇.rar73.《VISUAL BASIC 编程标准》/book/vb.zip74.《Visual Basic6.0中文版程序员指南》/diannao/download/prog/vb/zwbc.zip75.《Visual Basic 6.0 控件参考手册》/diannao/download/prog/vb/kjck.zip76.《Visual Basic 6.0中文版语言参考手册》/diannao/download/prog/vb/zwby.zip77.《Visual Basic 6.0 开发宝典》/diannao/download/prog/vb/kfbd.zip78.《Visual Basic 6.0 实例教程》/diannao/download/prog/vb/sljc.zip79.《VB 6.0 中文版实用参考手册》/diannao/download/prog/vb/syck.zip80.《Visual Basic 6开发人员指南》/diannao/download/prog/vb/kfzn.zip81.《VB 和SQL Server 编程指南(第五版)》/diannao/download/prog/vb/bczn.zip82.《Jbuilder 5 中文帮助》/download.asp?downid=2&id=99183.《JBuilder开发人员指南》/book/list_down.php?bkid=22484.《Win32的Internet函数说明》档案大小:245248K/diannao/download/prog/windows/win32int.zip85.《Visual InterDev 从入门到精通》/diannao/download/prog/interdev/crmd.wdl86.《Visual InterDev 6.0 Web 参考手册》/diannao/download/prog/interdev/jsck.zip87.《Visual InterDev 6.0 Guide 程序员》/diannao/download/prog/interdev/cxyz.zip88.《JavaScript 程序开发手册》/Templet/bookdownmore.asp?booktype=script#89.《JAVA 大全》/diannao/download/prog/java/cxkf.zip90.《Visual J++ 6.0 WFC 类库参考手册》/diannao/download/prog/java/lkck.zip91.《Java联想(中文)》/diannao/download/prog/java/lkck.zip92.《Oracle 8 实用大全》/diannao/download/prog/oracle/sydq.zip93.《Microsoft SQL Server 管理员手册》/diannao/download/prog/sql/glys.zip94.《掌握ACCESS开发》/diannao/download/prog/sql/glys.zip95.《Oracle Performance Tuning and Optimization》/book/oracle_pt.zip96.《Oracle ProC 程序设计》/book/oracleproc.zip97.《Oracle8初学者指南》/diannao/download/prog/oracle/cxzz.zip98.《RED HAT LINUX 6大全》/book/redhatall.zip99.《RED HAT LINUX 6管理工具》/book/redhatman.zip100.《VC++高级编程》/diannao/download/prog/c/vcgj.zip QQ群:12418867。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

STL source 1 G++ 2.91.57,cygnus\cygwin-b20\include\g++\stl_iterator.h 完整列表/*** Copyright (c) 1994* Hewlett-Packard Company** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Hewlett-Packard Company makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty.*** Copyright (c) 1996,1997* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation. Silicon Graphics makes no* representations about the suitability of this software for any* purpose. It is provided "as is" without express or implied warranty.*//* NOTE: This is an internal header file, included by other STL headers.* You should not attempt to use it directly.*/#ifndef __SGI_STL_INTERNAL_ITERATOR_H#define __SGI_STL_INTERNAL_ITERATOR_H__STL_BEGIN_NAMESPACEstruct input_iterator_tag {};struct output_iterator_tag {};struct forward_iterator_tag : public input_iterator_tag {};struct bidirectional_iterator_tag : public forward_iterator_tag {};struct random_access_iterator_tag : public bidirectional_iterator_tag {};template <class T, class Distance> struct input_iterator {typedef input_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef T* pointer;typedef T& reference;2STL source };struct output_iterator {typedef output_iterator_tag iterator_category;typedef void value_type;typedef void difference_type;typedef void pointer;typedef void reference;};template <class T, class Distance> struct forward_iterator {typedef forward_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef T* pointer;typedef T& reference;};template <class T, class Distance> struct bidirectional_iterator {typedef bidirectional_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef T* pointer;typedef T& reference;};template <class T, class Distance> struct random_access_iterator {typedef random_access_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef T* pointer;typedef T& reference;};#ifdef __STL_USE_NAMESPACEStemplate <class Category, class T, class Distance = ptrdiff_t,class Pointer = T*, class Reference = T&>struct iterator {typedef Category iterator_category;typedef T value_type;typedef Distance difference_type;typedef Pointer pointer;typedef Reference reference;};#endif /* __STL_USE_NAMESPACES */#ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONSTL source 3template <class Iterator>struct iterator_traits {typedef typename Iterator::iterator_category iterator_category;typedef typename Iterator::value_type value_type;typedef typename Iterator::difference_type difference_type;typedef typename Iterator::pointer pointer;typedef typename Iterator::reference reference;};template <class T>struct iterator_traits<T*> {typedef random_access_iterator_tag iterator_category;typedef T value_type;typedef ptrdiff_t difference_type;typedef T* pointer;typedef T& reference;};template <class T>struct iterator_traits<const T*> {typedef random_access_iterator_tag iterator_category;typedef T value_type;typedef ptrdiff_t difference_type;typedef const T* pointer;typedef const T& reference;};template <class Iterator>inline typename iterator_traits<Iterator>::iterator_categoryiterator_category(const Iterator&) {typedef typename iterator_traits<Iterator>::iterator_category category;return category();}template <class Iterator>inline typename iterator_traits<Iterator>::difference_type*distance_type(const Iterator&) {return static_cast<typename iterator_traits<Iterator>::difference_type*>(0);}template <class Iterator>inline typename iterator_traits<Iterator>::value_type*value_type(const Iterator&) {return static_cast<typename iterator_traits<Iterator>::value_type*>(0);}#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class T, class Distance>4STL sourceinline input_iterator_tagiterator_category(const input_iterator<T, Distance>&) {return input_iterator_tag();}inline output_iterator_tag iterator_category(const output_iterator&) {return output_iterator_tag();}template <class T, class Distance>inline forward_iterator_tagiterator_category(const forward_iterator<T, Distance>&) {return forward_iterator_tag();}template <class T, class Distance>inline bidirectional_iterator_tagiterator_category(const bidirectional_iterator<T, Distance>&) {return bidirectional_iterator_tag();}template <class T, class Distance>inline random_access_iterator_tagiterator_category(const random_access_iterator<T, Distance>&) {return random_access_iterator_tag();}template <class T>inline random_access_iterator_tag iterator_category(const T*) {return random_access_iterator_tag();}template <class T, class Distance>inline T* value_type(const input_iterator<T, Distance>&) {return (T*)(0);}template <class T, class Distance>inline T* value_type(const forward_iterator<T, Distance>&) {return (T*)(0);}template <class T, class Distance>inline T* value_type(const bidirectional_iterator<T, Distance>&) {return (T*)(0);}template <class T, class Distance>inline T* value_type(const random_access_iterator<T, Distance>&) {STL source 5return (T*)(0);}template <class T>inline T* value_type(const T*) { return (T*)(0); }template <class T, class Distance>inline Distance* distance_type(const input_iterator<T, Distance>&) {return (Distance*)(0);}template <class T, class Distance>inline Distance* distance_type(const forward_iterator<T, Distance>&) {return (Distance*)(0);}template <class T, class Distance>inline Distance*distance_type(const bidirectional_iterator<T, Distance>&) {return (Distance*)(0);}template <class T, class Distance>inline Distance*distance_type(const random_access_iterator<T, Distance>&) {return (Distance*)(0);}template <class T>inline ptrdiff_t* distance_type(const T*) { return (ptrdiff_t*)(0); }#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class InputIterator, class Distance>inline void __distance(InputIterator first, InputIterator last, Distance& n,input_iterator_tag) {while (first != last) { ++first; ++n; }}template <class RandomAccessIterator, class Distance>inline void __distance(RandomAccessIterator first, RandomAccessIterator last,Distance& n, random_access_iterator_tag) {n += last - first;}template <class InputIterator, class Distance>inline void distance(InputIterator first, InputIterator last, Distance& n) {__distance(first, last, n, iterator_category(first));}6STL source #ifdef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class InputIterator>inline iterator_traits<InputIterator>::difference_type__distance(InputIterator first, InputIterator last, input_iterator_tag) {iterator_traits<InputIterator>::difference_type n = 0;while (first != last) {++first; ++n;}return n;}template <class RandomAccessIterator>inline iterator_traits<RandomAccessIterator>::difference_type__distance(RandomAccessIterator first, RandomAccessIterator last,random_access_iterator_tag) {return last - first;}template <class InputIterator>inline iterator_traits<InputIterator>::difference_typedistance(InputIterator first, InputIterator last) {typedef typename iterator_traits<InputIterator>::iterator_category category;return __distance(first, last, category());}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class InputIterator, class Distance>inline void __advance(InputIterator& i, Distance n, input_iterator_tag) {while (n--) ++i;}#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)#pragma set woff 1183#endiftemplate <class BidirectionalIterator, class Distance>inline void __advance(BidirectionalIterator& i, Distance n,bidirectional_iterator_tag) {if (n >= 0)while (n--) ++i;elsewhile (n++) --i;}#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)#pragma reset woff 1183STL source 7 #endiftemplate <class RandomAccessIterator, class Distance>inline void __advance(RandomAccessIterator& i, Distance n,random_access_iterator_tag) {i += n;}template <class InputIterator, class Distance>inline void advance(InputIterator& i, Distance n) {__advance(i, n, iterator_category(i));}template <class Container>class back_insert_iterator {protected:Container* container;public:typedef output_iterator_tag iterator_category;typedef void value_type;typedef void difference_type;typedef void pointer;typedef void reference;explicit back_insert_iterator(Container& x) : container(&x) {}back_insert_iterator<Container>&operator=(const typename Container::value_type& value) {container->push_back(value);return *this;}back_insert_iterator<Container>& operator*() { return *this; }back_insert_iterator<Container>& operator++() { return *this; }back_insert_iterator<Container>& operator++(int) { return *this; }};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class Container>inline output_iterator_tagiterator_category(const back_insert_iterator<Container>&){return output_iterator_tag();}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class Container>inline back_insert_iterator<Container> back_inserter(Container& x) {return back_insert_iterator<Container>(x);8STL source }template <class Container>class front_insert_iterator {protected:Container* container;public:typedef output_iterator_tag iterator_category;typedef void value_type;typedef void difference_type;typedef void pointer;typedef void reference;explicit front_insert_iterator(Container& x) : container(&x) {}front_insert_iterator<Container>&operator=(const typename Container::value_type& value) {container->push_front(value);return *this;}front_insert_iterator<Container>& operator*() { return *this; }front_insert_iterator<Container>& operator++() { return *this; }front_insert_iterator<Container>& operator++(int) { return *this; }};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class Container>inline output_iterator_tagiterator_category(const front_insert_iterator<Container>&){return output_iterator_tag();}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class Container>inline front_insert_iterator<Container> front_inserter(Container& x) {return front_insert_iterator<Container>(x);}template <class Container>class insert_iterator {protected:Container* container;typename Container::iterator iter;public:typedef output_iterator_tag iterator_category;typedef void value_type;typedef void difference_type;STL source 9typedef void pointer;typedef void reference;insert_iterator(Container& x, typename Container::iterator i): container(&x), iter(i) {}insert_iterator<Container>&operator=(const typename Container::value_type& value) {iter = container->insert(iter, value);++iter;return *this;}insert_iterator<Container>& operator*() { return *this; }insert_iterator<Container>& operator++() { return *this; }insert_iterator<Container>& operator++(int) { return *this; }};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class Container>inline output_iterator_tagiterator_category(const insert_iterator<Container>&){return output_iterator_tag();}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class Container, class Iterator>inline insert_iterator<Container> inserter(Container& x, Iterator i) {typedef typename Container::iterator iter;return insert_iterator<Container>(x, iter(i));}#ifndef __STL_LIMITED_DEFAULT_TEMPLATEStemplate <class BidirectionalIterator, class T, class Reference = T&,class Distance = ptrdiff_t>#elsetemplate <class BidirectionalIterator, class T, class Reference,class Distance>#endifclass reverse_bidirectional_iterator {typedef reverse_bidirectional_iterator<BidirectionalIterator, T, Reference,Distance> self;protected:BidirectionalIterator current;public:typedef bidirectional_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;10STL sourcetypedef T* pointer;typedef Reference reference;reverse_bidirectional_iterator() {}explicit reverse_bidirectional_iterator(BidirectionalIterator x): current(x) {}BidirectionalIterator base() const { return current; }Reference operator*() const {BidirectionalIterator tmp = current;return *--tmp;}#ifndef __SGI_STL_NO_ARROW_OPERATORpointer operator->() const { return &(operator*()); }#endif /* __SGI_STL_NO_ARROW_OPERATOR */self& operator++() {--current;return *this;}self operator++(int) {self tmp = *this;--current;return tmp;}self& operator--() {++current;return *this;}self operator--(int) {self tmp = *this;++current;return tmp;}};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class BidirectionalIterator, class T, class Reference,class Distance>inline bidirectional_iterator_tagiterator_category(const reverse_bidirectional_iterator<BidirectionalIterator,T,Reference, Distance>&) {return bidirectional_iterator_tag();}template <class BidirectionalIterator, class T, class Reference,class Distance>inline T*value_type(const reverse_bidirectional_iterator<BidirectionalIterator, T,STL source 11Reference, Distance>&) {return (T*) 0;}template <class BidirectionalIterator, class T, class Reference,class Distance>inline Distance*distance_type(const reverse_bidirectional_iterator<BidirectionalIterator, T,Reference, Distance>&) {return (Distance*) 0;}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class BidirectionalIterator, class T, class Reference,class Distance>inline bool operator==(const reverse_bidirectional_iterator<BidirectionalIterator, T, Reference,Distance>& x,const reverse_bidirectional_iterator<BidirectionalIterator, T, Reference,Distance>& y) {return x.base() == y.base();}#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION// This is the new version of reverse_iterator, as defined in the// draft C++ standard. It relies on the iterator_traits template,// which in turn relies on partial specialization. The class// reverse_bidirectional_iterator is no longer part of the draft// standard, but it is retained for backward compatibility.template <class Iterator>class reverse_iterator{protected:Iterator current;public:typedef typename iterator_traits<Iterator>::iterator_categoryiterator_category;typedef typename iterator_traits<Iterator>::value_typevalue_type;typedef typename iterator_traits<Iterator>::difference_typedifference_type;typedef typename iterator_traits<Iterator>::pointerpointer;typedef typename iterator_traits<Iterator>::referencereference;12STL sourcetypedef Iterator iterator_type;typedef reverse_iterator<Iterator> self;public:reverse_iterator() {}explicit reverse_iterator(iterator_type x) : current(x) {}reverse_iterator(const self& x) : current(x.current) {}#ifdef __STL_MEMBER_TEMPLATEStemplate <class Iter>reverse_iterator(const reverse_iterator<Iter>& x) : current(x.current) {}#endif /* __STL_MEMBER_TEMPLATES */iterator_type base() const { return current; }reference operator*() const {Iterator tmp = current;return *--tmp;}#ifndef __SGI_STL_NO_ARROW_OPERATORpointer operator->() const { return &(operator*()); }#endif /* __SGI_STL_NO_ARROW_OPERATOR */self& operator++() {--current;return *this;}self operator++(int) {self tmp = *this;--current;return tmp;}self& operator--() {++current;return *this;}self operator--(int) {self tmp = *this;++current;return tmp;}self operator+(difference_type n) const {return self(current - n);}self& operator+=(difference_type n) {current -= n;return *this;}self operator-(difference_type n) const {STL source 13return self(current + n);}self& operator-=(difference_type n) {current += n;return *this;}reference operator[](difference_type n) const { return *(*this + n); }};template <class Iterator>inline bool operator==(const reverse_iterator<Iterator>& x,const reverse_iterator<Iterator>& y) {return x.base() == y.base();}template <class Iterator>inline bool operator<(const reverse_iterator<Iterator>& x,const reverse_iterator<Iterator>& y) {return y.base() < x.base();}template <class Iterator>inline typename reverse_iterator<Iterator>::difference_typeoperator-(const reverse_iterator<Iterator>& x,const reverse_iterator<Iterator>& y) {return y.base() - x.base();}template <class Iterator>inline reverse_iterator<Iterator>operator+(reverse_iterator<Iterator>::difference_type n,const reverse_iterator<Iterator>& x) {return reverse_iterator<Iterator>(x.base() - n);}#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */// This is the old version of reverse_iterator, as found in the original// HP STL. It does not use partial specialization.#ifndef __STL_LIMITED_DEFAULT_TEMPLATEStemplate <class RandomAccessIterator, class T, class Reference = T&,class Distance = ptrdiff_t>#elsetemplate <class RandomAccessIterator, class T, class Reference,class Distance>#endifclass reverse_iterator {typedef reverse_iterator<RandomAccessIterator, T, Reference, Distance>14STL sourceself;protected:RandomAccessIterator current;public:typedef random_access_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef T* pointer;typedef Reference reference;reverse_iterator() {}explicit reverse_iterator(RandomAccessIterator x) : current(x) {}RandomAccessIterator base() const { return current; }Reference operator*() const { return *(current - 1); }#ifndef __SGI_STL_NO_ARROW_OPERATORpointer operator->() const { return &(operator*()); }#endif /* __SGI_STL_NO_ARROW_OPERATOR */self& operator++() {--current;return *this;}self operator++(int) {self tmp = *this;--current;return tmp;}self& operator--() {++current;return *this;}self operator--(int) {self tmp = *this;++current;return tmp;}self operator+(Distance n) const {return self(current - n);}self& operator+=(Distance n) {current -= n;return *this;}self operator-(Distance n) const {return self(current + n);}self& operator-=(Distance n) {current += n;return *this;}STL source 15Reference operator[](Distance n) const { return *(*this + n); }};template <class RandomAccessIterator, class T, class Reference, class Distance> inline random_access_iterator_tagiterator_category(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>&) {return random_access_iterator_tag();}template <class RandomAccessIterator, class T, class Reference, class Distance> inline T* value_type(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>&) {return (T*) 0;}template <class RandomAccessIterator, class T, class Reference, class Distance> inline Distance* distance_type(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>&) {return (Distance*) 0;}template <class RandomAccessIterator, class T, class Reference, class Distance> inline bool operator==(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& x,const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& y) {return x.base() == y.base();}template <class RandomAccessIterator, class T, class Reference, class Distance> inline bool operator<(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& x,const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& y) {return y.base() < x.base();}template <class RandomAccessIterator, class T, class Reference, class Distance> inline Distance operator-(const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& x,const reverse_iterator<RandomAccessIterator, T,Reference, Distance>& y) {return y.base() - x.base();}template <class RandomAccessIter, class T, class Ref, class Dist>inline reverse_iterator<RandomAccessIter, T, Ref, Dist>16STL sourceoperator+(Dist n, const reverse_iterator<RandomAccessIter, T, Ref, Dist>& x) {return reverse_iterator<RandomAccessIter, T, Ref, Dist>(x.base() - n);}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class T, class Distance = ptrdiff_t>class istream_iterator {friend booloperator== __STL_NULL_TMPL_ARGS (const istream_iterator<T, Distance>& x,const istream_iterator<T, Distance>& y);protected:istream* stream;T value;bool end_marker;void read() {end_marker = (*stream) ? true : false;if (end_marker) *stream >> value;end_marker = (*stream) ? true : false;}public:typedef input_iterator_tag iterator_category;typedef T value_type;typedef Distance difference_type;typedef const T* pointer;typedef const T& reference;istream_iterator() : stream(&cin), end_marker(false) {}istream_iterator(istream& s) : stream(&s) { read(); }reference operator*() const { return value; }#ifndef __SGI_STL_NO_ARROW_OPERATORpointer operator->() const { return &(operator*()); }#endif /* __SGI_STL_NO_ARROW_OPERATOR */istream_iterator<T, Distance>& operator++() {read();return *this;}istream_iterator<T, Distance> operator++(int) {istream_iterator<T, Distance> tmp = *this;read();return tmp;}};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class T, class Distance>inline input_iterator_tagiterator_category(const istream_iterator<T, Distance>&) {STL source 17return input_iterator_tag();}template <class T, class Distance>inline T* value_type(const istream_iterator<T, Distance>&) { return (T*) 0; }template <class T, class Distance>inline Distance* distance_type(const istream_iterator<T, Distance>&) {return (Distance*) 0;}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class T, class Distance>inline bool operator==(const istream_iterator<T, Distance>& x,const istream_iterator<T, Distance>& y) {return x.stream == y.stream && x.end_marker == y.end_marker ||x.end_marker == false && y.end_marker == false;}template <class T>class ostream_iterator {protected:ostream* stream;const char* string;public:typedef output_iterator_tag iterator_category;typedef void value_type;typedef void difference_type;typedef void pointer;typedef void reference;ostream_iterator(ostream& s) : stream(&s), string(0) {}ostream_iterator(ostream& s, const char* c) : stream(&s), string(c) {}ostream_iterator<T>& operator=(const T& value) {*stream << value;if (string) *stream << string;return *this;}ostream_iterator<T>& operator*() { return *this; }ostream_iterator<T>& operator++() { return *this; }ostream_iterator<T>& operator++(int) { return *this; }};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class T>inline output_iterator_tagiterator_category(const ostream_iterator<T>&) {18STL sourcereturn output_iterator_tag();}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */__STL_END_NAMESPACE#endif /* __SGI_STL_INTERNAL_ITERATOR_H */// Local Variables:// mode:C++// End:。

相关文档
最新文档