├── README.md ├── SGI-STL Test ├── .editorconfig ├── README.md ├── adapter_test │ ├── README.md │ └── adapter_test1 │ │ └── adapter_test1.cpp ├── algorithm_test │ ├── README.md │ └── algorithm_test1 │ │ └── algorithm_test1.cpp ├── allocator_test │ ├── README.md │ └── myAllocator │ │ ├── myAllocator.cpp │ │ └── myAllocator.h ├── container_test │ ├── README.md │ ├── deque_test │ │ └── deque_test.cpp │ ├── forward_list │ │ └── forward_list.cpp │ ├── hash_map │ │ └── hash_map.cpp │ ├── hash_set │ │ └── hash_set.cpp │ ├── heap_test │ │ └── heap_test.cpp │ ├── list_test │ │ └── list_test.cpp │ ├── map_test │ │ └── map_test.cpp │ ├── priority_queue_test │ │ └── priority_queue_test.cpp │ ├── queue_test │ │ └── queue_test.cpp │ ├── set_test │ │ └── set_test.cpp │ ├── stack_test │ │ └── stack_test.cpp │ └── vector_test │ │ └── vector_test.cpp ├── functor_test │ ├── README.md │ └── functionObject.cpp └── iterator_test │ ├── README.md │ ├── find │ └── find.cpp │ └── iterator_traits_reverse │ └── iterator_traits_reverse.cpp ├── SGI-STL V3.3 ├── algo.h ├── algobase.h ├── algorithm ├── alloc.h ├── bitset ├── bvector.h ├── char_traits.h ├── concept_checks.h ├── container_concepts.h ├── defalloc.h ├── deque ├── deque.h ├── function.h ├── functional ├── hash_map ├── hash_map.h ├── hash_set ├── hash_set.h ├── hashtable.h ├── heap.h ├── iterator ├── iterator.h ├── limits ├── list ├── list.h ├── map ├── map.h ├── memory ├── multimap.h ├── multiset.h ├── numeric ├── pair.h ├── pthread_alloc ├── pthread_alloc.h ├── queue ├── rope ├── rope.h ├── ropeimpl.h ├── sequence_concepts.h ├── set ├── set.h ├── slist ├── slist.h ├── stack ├── stack.h ├── stdexcept ├── stl_algo.h ├── stl_algobase.h ├── stl_alloc.h ├── stl_bvector.h ├── stl_config.h ├── stl_construct.h ├── stl_ctraits_fns.h ├── stl_deque.h ├── stl_exception.h ├── stl_function.h ├── stl_hash_fun.h ├── stl_hash_map.h ├── stl_hash_set.h ├── stl_hashtable.h ├── stl_heap.h ├── stl_iterator.h ├── stl_iterator_base.h ├── stl_list.h ├── stl_map.h ├── stl_multimap.h ├── stl_multiset.h ├── stl_numeric.h ├── stl_pair.h ├── stl_queue.h ├── stl_range_errors.h ├── stl_raw_storage_iter.h ├── stl_relops.h ├── stl_rope.h ├── stl_set.h ├── stl_slist.h ├── stl_stack.h ├── stl_string_fwd.h ├── stl_tempbuf.h ├── stl_threads.h ├── stl_tree.h ├── stl_uninitialized.h ├── stl_vector.h ├── string ├── tempbuf.h ├── tree.h ├── type_traits.h ├── utility ├── valarray ├── vector └── vector.h └── The Annotated STL Sources V3.3 ├── Other ├── RBTree.PNG ├── README.md ├── SGISTL.PNG ├── STLAlgorithm.png ├── adapter.PNG ├── allocator.PNG ├── allocator_memorypool.PNG ├── associativecontainer.PNG ├── container.PNG ├── deque DS.PNG ├── deque.PNG ├── functionobject.png ├── iteratortraits.PNG ├── list.PNG ├── queue.PNG ├── sequencecontainer.PNG ├── stack.PNG ├── stl_config.h └── vector.PNG ├── README.md ├── adapter └── README.md ├── algorithm ├── README.md ├── algo.h ├── algobase.h ├── algorithm ├── numeric ├── stl_algo.h ├── stl_algobase.h └── stl_numeric.h ├── allocator ├── README.md ├── alloc.h ├── defalloc.h ├── stl_alloc.h ├── stl_construct.h └── stl_uninitialized.h ├── container ├── README.md ├── associative container │ ├── RB-tree │ │ ├── README.md │ │ ├── stl_tree.h │ │ └── tree.h │ ├── README.md │ ├── hash_map │ │ ├── README.md │ │ ├── hash_map │ │ ├── hash_map.h │ │ └── stl_hash_map.h │ ├── hash_set │ │ ├── README.md │ │ ├── hash_set │ │ ├── hash_set.h │ │ └── stl_hash_set.h │ ├── hashtable │ │ ├── README.md │ │ ├── hashtable.h │ │ ├── stl_hash_fun.h │ │ └── stl_hashtable.h │ ├── map │ │ ├── README.md │ │ ├── map │ │ ├── map.h │ │ ├── pair.h │ │ ├── stl_map.h │ │ └── stl_pair.h │ ├── multimap │ │ ├── multimap.h │ │ └── stl_multimap.h │ ├── multiset │ │ ├── multiset.h │ │ └── stl_multiset.h │ └── set │ │ ├── README.md │ │ ├── bitset │ │ ├── set │ │ ├── set.h │ │ └── stl_set.h └── sequence container │ ├── README.md │ ├── deque │ ├── README.md │ ├── deque │ ├── deque.h │ └── stl_deque.h │ ├── heap │ ├── README.md │ ├── heap.h │ └── stl_heap.h │ ├── list │ ├── README.md │ ├── list │ ├── list.h │ └── stl_list.h │ ├── queue │ ├── README.md │ ├── queue │ └── stl_queue.h │ ├── slist │ ├── README.md │ ├── slist │ ├── slist.h │ └── stl_slist.h │ ├── stack │ ├── README.md │ ├── stack │ ├── stack.h │ └── stl_stack.h │ └── vector │ ├── README.md │ ├── bvector.h │ ├── stl_bvector.h │ ├── stl_vector.h │ ├── vector │ └── vector.h ├── functor-function object ├── README.md ├── function.h ├── functional └── stl_function.h └── iterator ├── README.md ├── iterator ├── iterator.h ├── memory ├── stl_iterator.h ├── stl_iterator_base.h ├── stl_raw_storage_iter.h └── type_traits.h /README.md: -------------------------------------------------------------------------------- 1 | ## SGI-STL V3.3 源代码的学习 2 | 3 | * SGI-STL V3.3(源代码) 4 | + STL 标准头文件(无扩展名),例如 `vector`,`deque`,`list`... 5 | + C++ Standard 定案前,HP 规范的 STL 头文件(扩展名 .h) 6 | + SGI STL 内部私用文件(SGI STL 真正实现于此) 7 | 8 | * The Annotated STL Sources V3.3(学习源代码的注释) 9 | + [容器 (container)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/container) :序列式容器 (sequence container) 和 关联式容器 (associattive container) 10 | + [算法 (algorithm)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/algorithm) 11 | + [迭代器 (iterator)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/iterator) 12 | + [仿函数或函数对象 (functor / function object)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/functor-function%20object) 13 | + [配接器(adapter)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/adapter) 14 | + [配置器(allocator)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/allocator) 15 | 16 | * SGI-STL Test(代码测试) 17 | 18 | + [Code Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test) 19 | 20 | ## GCC 编译器 21 | 22 | SGI STL 被归纳到 GNU C++ 标准程序库中,例如 gcc 使用 4.8.4 版本,STL源码 在 Linux 系统的位置是:/usr/include/c++/4.8.4/bits。 23 | 24 | ## 参考资料 25 | 26 | * <> 侯捷 27 | -------------------------------------------------------------------------------- /SGI-STL Test/.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # all files 5 | [*] 6 | indent_style = tab 7 | indent_size = 4 8 | -------------------------------------------------------------------------------- /SGI-STL Test/README.md: -------------------------------------------------------------------------------- 1 | ## SGI-STL Code Test 2 | 3 | SGI STL 六大组件的代码测试 4 | 5 | * [配置器(allocator)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/allocator_test) 6 | * [迭代器(iterator)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/iterator_test) 7 | * [容器(container)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test) 8 | * [算法(algorithm)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/algorithm_test) 9 | * [仿函数(functor)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/functor_test) 10 | * [配接器(adapter)-Test](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/adapter_test) 11 | 12 | 在 gcc version 4.8.4 下编译,C++11 标准,编译带 `-std=c++11` 13 | 14 | ## 参考 15 | 16 | * [C++ reference](http://en.cppreference.com/w/) 17 | -------------------------------------------------------------------------------- /SGI-STL Test/adapter_test/README.md: -------------------------------------------------------------------------------- 1 | ## 配接器(adapter)-Code Test 2 | -------------------------------------------------------------------------------- /SGI-STL Test/adapter_test/adapter_test1/adapter_test1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | string s = "AdapterTest"; 13 | 14 | reverse_iterator r = s.rbegin(); 15 | 16 | string rev(r, s.rend()); 17 | 18 | cout << rev << "\n"; 19 | 20 | vector v1{1, 5, 16, 8}; 21 | 22 | fill_n(back_inserter(v1), 3, -1); // 用于添加元素到容器的尾部 23 | for (auto n : v1) { 24 | cout << n << " "; 25 | } 26 | cout << "\n"; 27 | 28 | deque v2{1, 5, 16, 8}; 29 | fill_n(front_inserter(v2), 3, -1); // 用于添加元素到容器的起始 30 | for (auto n : v2) { 31 | cout << n << " "; 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /SGI-STL Test/algorithm_test/README.md: -------------------------------------------------------------------------------- 1 | ## 算法(algorithm)-Code Test 2 | -------------------------------------------------------------------------------- /SGI-STL Test/algorithm_test/algorithm_test1/algorithm_test1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | vector v{5, 1, 21, 3, 8, 15, 6}; 10 | 11 | auto result1 = find(begin(v), end(v), 1); 12 | auto result2 = find(begin(v), end(v), 12); 13 | 14 | if (result1 != v.end()) { 15 | cout << "vector contain 1" << endl; 16 | } else { 17 | cout << "vector don't contain 1" << endl; 18 | } 19 | 20 | if (result2 != v.end()) { 21 | cout << "vector contain 12" << endl; 22 | } else { 23 | cout << "vector don't contain 12" << endl; 24 | } 25 | 26 | sort(v.begin(), v.end()); 27 | for (auto n : v) { 28 | cout << n << " "; 29 | } 30 | cout << endl; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /SGI-STL Test/allocator_test/README.md: -------------------------------------------------------------------------------- 1 | ## 配置器(allocator)-Code Test 2 | 3 | * [myAllocator](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/allocator_test/myAllocator) 4 | -------------------------------------------------------------------------------- /SGI-STL Test/allocator_test/myAllocator/myAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "myAllocator.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // myAllocator test 8 | int main() 9 | { 10 | int arr[5] = {0, 1, 2, 3, 4}; 11 | 12 | vector > iv(arr, arr + 5); 13 | 14 | for (size_t i = 0; i < iv.size(); i++) { 15 | cout << iv[i] << ' '; 16 | } 17 | 18 | cout << endl; 19 | } 20 | -------------------------------------------------------------------------------- /SGI-STL Test/allocator_test/myAllocator/myAllocator.h: -------------------------------------------------------------------------------- 1 | #ifndef MY_ALLOCATOR_H 2 | #define MY_ALLOCATOR_H 3 | 4 | #include // placement new 5 | #include // ptrdiff_t, size_t 6 | #include // exit() 7 | #include // UINT_MAX 8 | #include // cerr 9 | 10 | // 一个简单的空间配置器 11 | namespace myAllocator 12 | { 13 | // 空间的分配,可以存储 size 个 T 对象 14 | template 15 | inline T* _allocate(ptrdiff_t size, T*) { 16 | std::set_new_handler(0); // 分配失败,抛出std::bad_alloc 17 | 18 | // 空间的分配实现,调用 ::operator new() 全局函数 19 | T* tmp = (T*)(::operator new((size_t)(size * sizeof(T)))); 20 | 21 | if (tmp == 0) { 22 | std::cerr << "out of memory" << std::endl; 23 | exit(1); 24 | } 25 | 26 | return tmp; 27 | } 28 | 29 | // 空间的释放,调用 ::operator delete() 全局函数 30 | template 31 | inline void _deallocate(T* buffer) { 32 | ::operator delete(buffer); 33 | } 34 | 35 | // 对象的构造 36 | template 37 | inline void _construct(T1* p, const T2& value) 38 | { 39 | new(p) T1(value); // placement new 40 | } 41 | 42 | // 对象的析构 43 | template 44 | inline void _destroy(T* ptr) { 45 | ptr->~T(); 46 | } 47 | 48 | // 提供外部使用 allocator 49 | template 50 | class allocator { 51 | public: 52 | // 对象的类型 53 | typedef T value_type; 54 | typedef T* pointer; 55 | typedef const T* const_pointer; 56 | typedef T& reference; 57 | typedef const T& const_reference; 58 | typedef size_t size_type; 59 | typedef ptrdiff_t difference_type; // ptrdiff_t 是两个指针相减结果的有符号整数类型 60 | 61 | // 嵌套 allocator 62 | template 63 | struct rebind { 64 | typedef allocator other; 65 | }; 66 | 67 | /*** 68 | * 以下四个函数提供外部使用,空间的分配和释放,对象的构造和析构 69 | */ 70 | pointer allocate(size_type n, const void* hint = 0) { 71 | return _allocate((difference_type)n, (pointer)0); 72 | } 73 | 74 | void deallocate(pointer p, size_type n) { 75 | _deallocate(p); 76 | } 77 | 78 | void construct(pointer p, const T& value) { 79 | _construct(p, value); 80 | } 81 | 82 | void destroy(pointer p) { 83 | _destroy(p); 84 | } 85 | 86 | // 返回某个对象的地址 87 | pointer address(reference x) { 88 | return (pointer)&x; 89 | } 90 | 91 | // 返回某个 const 对象的地址 92 | const_pointer const_address(const_reference x) { 93 | return (const_pointer)&x; 94 | } 95 | 96 | // 返回可成功分配的最大量 97 | size_type max_size() const { 98 | return size_type(UINT_MAX/sizeof(T)); // UINT_MAX 是 unsigned long 及 unsigned long long 的最大值 99 | } 100 | }; 101 | } 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/README.md: -------------------------------------------------------------------------------- 1 | ## 容器(container)-Code Test 2 | 3 | * [vector](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/vector_test) 4 | 5 | * [list](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/list_test) 6 | 7 | * [deque](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/deque_test) 8 | 9 | * [stack](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/stack_test) 10 | 11 | * [queue](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/queue_test) 12 | 13 | * [heap](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/heap_test) 14 | 15 | * [priority_queue](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/priority_queue_test) 16 | 17 | * [forward_list](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/forward_list) 18 | 19 | * [set](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/set_test) 20 | 21 | * [map](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/map_test) 22 | 23 | * [hash_set](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/hash_set) 24 | 25 | * [hash_map](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/container_test/hash_map) 26 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/deque_test/deque_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | // g++ deque_test.cpp -o deque_test -std=c++11 8 | template 9 | void printDeque(const deque& deq) 10 | { 11 | for (auto n : deq) { 12 | cout << n << " "; 13 | } 14 | 15 | cout << endl; 16 | } 17 | 18 | int main() 19 | { 20 | // deque 构造函数 21 | deque words1{"The", "is", "deque"}; 22 | printDeque(words1); 23 | 24 | deque words2(words1.begin(), words1.end()); 25 | printDeque(words2); 26 | 27 | deque words3(words1); 28 | printDeque(words3); 29 | 30 | deque words4(5, "YES"); 31 | printDeque(words4); 32 | 33 | // front 34 | cout << words1.front() << endl; 35 | 36 | // back 37 | cout << words1.back() << endl; 38 | 39 | // size 40 | cout << "words contains : " << words4.size() << endl; 41 | 42 | // push_back 43 | words4.push_back("NO"); 44 | printDeque(words4); 45 | 46 | // pop_back 47 | words4.pop_back(); 48 | printDeque(words4); 49 | 50 | // push_front 51 | words4.push_front("SS"); 52 | printDeque(words4); 53 | 54 | // pop_front 55 | words4.pop_front(); 56 | printDeque(words4); 57 | 58 | // erase 59 | words4.erase(words4.begin()); 60 | printDeque(words4); 61 | 62 | words1.erase(words1.begin()+2, words1.end()); 63 | printDeque(words1); 64 | 65 | // insert 66 | words1.insert(words1.begin()+1, words4.begin(), words4.end()); 67 | printDeque(words1); 68 | 69 | words1.insert(words1.begin()+3, "strat"); 70 | printDeque(words1); 71 | 72 | words1.insert(words1.begin()+3, 5, "IS"); 73 | printDeque(words1); 74 | 75 | // iterator 76 | for (deque::iterator it = words1.begin(); it != words1.end(); it++) { 77 | cout << *it << " "; 78 | } 79 | cout << endl; 80 | 81 | // reverse_iterator 82 | for (deque::reverse_iterator it = words1.rbegin(); it != words1.rend(); it++) { 83 | cout << *it << " "; 84 | } 85 | cout << endl; 86 | 87 | return 0; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/forward_list/forward_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /*** 8 | * slist 不是标准,C++11 加入 forward_list 容器,其为单链表 9 | */ 10 | template 11 | void printForward_list(forward_list& fl) 12 | { 13 | for (typename forward_list::iterator it = fl.begin(); it != fl.end(); it++) { 14 | cout << *it << " "; 15 | } 16 | 17 | cout << endl; 18 | } 19 | 20 | int main() 21 | { 22 | forward_list s{"why", "always", "me"}; 23 | 24 | printForward_list(s); 25 | 26 | s.push_front("what"); 27 | s.push_front("the"); 28 | 29 | printForward_list(s); 30 | 31 | forward_list::iterator it = find(s.begin(), s.end(), "always"); 32 | 33 | if (it != s.end()) { 34 | s.erase_after(s.before_begin()); // 没有 erase 功能 35 | } 36 | 37 | printForward_list(s); 38 | } 39 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/hash_map/hash_map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace __gnu_cxx; 6 | 7 | using namespace std; 8 | 9 | struct eqstr 10 | { 11 | bool operator() (const char* s1, const char* s2) const 12 | { 13 | return strcmp(s1, s2) == 0; 14 | } 15 | }; 16 | 17 | 18 | int main() 19 | { 20 | hash_map, eqstr> s; 21 | 22 | cout << s.size() << endl; 23 | 24 | s["why"] = 3; 25 | s["always"] = 4; 26 | s["me"] = 8; 27 | s["star"] = 9; 28 | s["steve"] = 18; 29 | 30 | cout << s.size() << endl; 31 | 32 | cout << "why -> " << s["why"] << endl; 33 | cout << "me -> " << s["me"] << endl; 34 | cout << "star -> " << s["star"] << endl; 35 | 36 | hash_map, eqstr>::iterator it = s.begin(); 37 | for (; it != s.end(); it++) { 38 | cout << it->first << " " << it->second << endl; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/hash_set/hash_set.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace __gnu_cxx; 6 | 7 | using namespace std; 8 | 9 | struct eqstr 10 | { 11 | bool operator() (const char* s1, const char* s2) const 12 | { 13 | return strcmp(s1, s2) == 0; 14 | } 15 | }; 16 | 17 | void setFind(const hash_set, eqstr>& s, const char* word) 18 | { 19 | hash_set, eqstr>::const_iterator it 20 | = s.find(word); 21 | 22 | cout << word << ": " << (it != s.end() ? "present" : "not present") << endl; 23 | } 24 | 25 | int main() 26 | { 27 | hash_set, eqstr> s; 28 | 29 | cout << s.size() << endl; 30 | 31 | s.insert("why"); 32 | s.insert("always"); 33 | s.insert("me"); 34 | s.insert("star"); 35 | s.insert("steve"); 36 | 37 | cout << s.size() << endl; 38 | 39 | setFind(s, "always"); 40 | setFind(s, "apple"); 41 | 42 | hash_set, eqstr>::iterator it = s.begin(); 43 | for (; it != s.end(); it++) { 44 | cout << *it << endl; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/heap_test/heap_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | template 8 | void printHeap(vector& ivec) 9 | { 10 | for (int i = 0; i < ivec.size(); i++) { 11 | cout << ivec[i] << " "; 12 | } 13 | 14 | cout << endl; 15 | } 16 | 17 | template 18 | void printArray(T arr[], size_t size) 19 | { 20 | for (size_t i = 0; i < size; i++) { 21 | cout << arr[i] << " "; 22 | } 23 | 24 | cout << endl; 25 | } 26 | 27 | int main() 28 | { 29 | // heap 底层使用 vector 容器 30 | vector iv{1, 5, 9, 3, 2, 0, 4}; 31 | 32 | // 调整为 heap 33 | make_heap(iv.begin(), iv.end()); 34 | 35 | printHeap(iv); 36 | 37 | // 对 vector 尾部插入 8 38 | iv.push_back(8); 39 | 40 | // 新插入 8,对 heap 重新调整 41 | push_heap(iv.begin(), iv.end()); 42 | 43 | printHeap(iv); 44 | 45 | // 将 vector 的首元素放到尾端 46 | pop_heap(iv.begin(), iv.end()); 47 | 48 | // vector 的操作 49 | cout << iv.back() << endl; 50 | 51 | iv.pop_back(); 52 | 53 | printHeap(iv); 54 | 55 | // 对 heap 排序 56 | sort_heap(iv.begin(), iv.end()); 57 | 58 | printHeap(iv); 59 | 60 | // heap 底层使用 array 数组 61 | int arr[] = {12, 34, 15, 63, 17}; 62 | 63 | make_heap(arr, arr+5); // array 大小一定,不能做 push_back 操作 64 | 65 | size_t arr_size = sizeof(arr) / sizeof(arr[0]); 66 | 67 | printArray(arr, arr_size); 68 | 69 | // 对 heap 排序 70 | sort_heap(arr, arr+5); 71 | 72 | printArray(arr, arr_size); 73 | } 74 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/map_test/map_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | template 7 | void printMap(T& m) 8 | { 9 | cout << "{ "; 10 | for (auto& n : m) { 11 | cout << n.first << " : " << n.second << " "; 12 | } 13 | 14 | cout << "}\n"; 15 | } 16 | 17 | int main() 18 | { 19 | // map 构造函数 20 | map simap; 21 | simap["why"] = 1; 22 | simap["always"] = 2; 23 | simap["me"] = 3; 24 | 25 | printMap(simap); 26 | 27 | // 插入操作 28 | pair value("steve", 4); 29 | simap.insert(value); 30 | 31 | printMap(simap); 32 | 33 | // operator[] 34 | int number = simap["steve"]; 35 | 36 | cout << "number = " << number << endl; 37 | // find 查找 38 | auto it = simap.find("why"); 39 | if (it != simap.end()) { 40 | cout << "why found" << endl; 41 | simap.erase(it); // erase 42 | } 43 | printMap(simap); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/priority_queue_test/priority_queue_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | template 9 | void printPQueue(priority_queue& ipq) 10 | { 11 | while (!ipq.empty()) { 12 | cout << ipq.top() << " "; 13 | ipq.pop(); 14 | } 15 | 16 | cout << endl; 17 | } 18 | 19 | int main() 20 | { 21 | vector iv{4, 8, 9, 7, 32, 12}; 22 | 23 | // priority_queue 构造函数,调整为 heap 24 | priority_queue ipq(iv.begin(), iv.end()); 25 | 26 | cout << "ipq size = " << ipq.size() << endl; 27 | 28 | printPQueue(ipq); // 调用完后,容器为空 29 | 30 | cout << "ipq size = " << ipq.size() << endl; 31 | 32 | // 向容器尾端插入元素,会重新调整 33 | ipq.push(1); 34 | ipq.push(100); 35 | ipq.push(12); 36 | ipq.push(44); 37 | 38 | cout << "ipq insert size = " << ipq.size() << endl; 39 | 40 | printPQueue(ipq); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/queue_test/queue_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | template 8 | void printQueue(queue& q) 9 | { 10 | int queue_size = q.size(); 11 | 12 | for (int i = 0; i < queue_size; i++) { 13 | cout << q.front() << " "; 14 | q.pop(); 15 | } 16 | 17 | cout << endl; 18 | } 19 | 20 | template 21 | void printlistQueue(queue >& q) { 22 | int queue_size = q.size(); 23 | 24 | for (int i = 0; i < queue_size; i++) { 25 | cout << q.front() << " "; 26 | q.pop(); 27 | } 28 | 29 | cout << endl; 30 | } 31 | 32 | int main() 33 | { 34 | // 默认以 queue 为底层容器 35 | queue q; 36 | 37 | q.push(1); 38 | q.push(2); 39 | q.push(3); 40 | 41 | cout << "size = " << q.size() << endl; 42 | 43 | printQueue(q); 44 | 45 | // 以 list 为底层容器 46 | queue > iq; 47 | 48 | iq.push("why"); 49 | iq.push("always"); 50 | iq.push("me"); 51 | 52 | cout << "iq size = " << iq.size() << endl; 53 | 54 | printlistQueue(iq); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/set_test/set_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | template 8 | void printSet(const set& s) 9 | { 10 | for (auto& n : s) { 11 | cout << n << " "; 12 | } 13 | 14 | cout << endl; 15 | } 16 | 17 | int main() 18 | { 19 | // 默认初始化 20 | set i; 21 | 22 | i.insert(8); 23 | i.insert(2); 24 | i.insert(5); 25 | 26 | printSet(i); 27 | 28 | // initializer_list 构造函数 29 | set s{"why", "always", "me"}; 30 | 31 | printSet(s); 32 | 33 | // 迭代器初始化器 34 | set d(s.find("me"), s.end()); 35 | 36 | printSet(d); 37 | 38 | // 复制构造函数 39 | set c(s); 40 | 41 | printSet(c); 42 | 43 | // STL find 44 | 45 | if (find(c.begin(), c.end(), "me") != c.end()) { 46 | cout << "found " << endl; 47 | } 48 | 49 | c.erase("why"); 50 | 51 | printSet(c); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/stack_test/stack_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | template 9 | void printStack(stack& s) 10 | { 11 | int stack_size = s.size(); 12 | 13 | for (int i = 0; i < stack_size; i++) { 14 | cout << s.top() << " "; 15 | 16 | s.pop(); 17 | } 18 | 19 | cout << endl; 20 | } 21 | 22 | template 23 | void printlistStack(stack >& s) 24 | { 25 | int stack_size = s.size(); 26 | for (int i = 0; i < stack_size; i++) { 27 | cout << s.top() << " "; 28 | 29 | s.pop(); 30 | } 31 | 32 | cout << endl; 33 | } 34 | 35 | int main() 36 | { 37 | // 默认以 deque 为底层容器 38 | stack s; 39 | 40 | s.push(1); 41 | s.push(2); 42 | s.push(3); 43 | 44 | cout << "size = " << s.size() << endl; 45 | 46 | printStack(s); 47 | 48 | // 以 list 为底层容器 49 | stack > istack; 50 | 51 | istack.push(5); 52 | istack.push(6); 53 | istack.push(7); 54 | 55 | cout << "istack size = " << istack.size() << endl; 56 | 57 | printlistStack(istack); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /SGI-STL Test/container_test/vector_test/vector_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | /** 7 | * vector 的操作 8 | */ 9 | template 10 | void printVector(const vector& vec) 11 | { 12 | for (auto x : vec) { 13 | cout << x << " "; 14 | } 15 | 16 | cout << endl; 17 | } 18 | 19 | int main() 20 | { 21 | // 构造函数:四种形式 22 | vector iv(2, "hi"); 23 | printVector(iv); 24 | 25 | vector sv{"why", "always", "me"}; 26 | printVector(sv); 27 | 28 | vector sv2(sv.begin(), sv.end()); 29 | printVector(sv2); 30 | 31 | vector sv3(sv); 32 | printVector(sv3); 33 | 34 | // operator= 赋值运算符 35 | vector sv4; 36 | sv4 = sv; 37 | printVector(sv4); 38 | 39 | // assign 40 | vector cv; 41 | cv.assign(5, 'x'); 42 | printVector(cv); 43 | 44 | vector cv1; 45 | cv1.assign(cv.begin(), cv.end()); 46 | printVector(cv1); 47 | 48 | // at(索引) 49 | cout << cv1.at(1) << endl; 50 | 51 | // operator[] 52 | cv1[1] = 'a'; 53 | printVector(cv1); 54 | 55 | // front 容器首元素 56 | cout << sv.front() << endl; 57 | 58 | // back 容器最后一个元素 59 | cout << sv.back() << endl; 60 | 61 | // begin 返回指向容器第一个元素的迭代器 62 | // end 返回指向容器尾端的迭代器 63 | for (vector::iterator it = sv.begin(); it != sv.end(); it++) { 64 | cout << *it << " "; 65 | } 66 | cout << endl; 67 | 68 | // rbegin 返回一个指向容器最后一个元素的反向迭代器 69 | // rend 返回一个指向容器前端的反向迭代器 70 | for (vector::reverse_iterator it = sv.rbegin(); it != sv.rend(); it++) { 71 | cout << *it << " "; 72 | } 73 | cout << endl; 74 | 75 | // empty 若容器为空则为 true ,否则为 false 76 | if (sv.empty()) { 77 | cout << "container is null." << endl; 78 | } else { 79 | cout << "container is not null." << endl; 80 | } 81 | 82 | // size 容器中的元素个数 83 | cout << sv.size() << endl; 84 | 85 | // max_size 元素数量的最大值 86 | cout << sv.max_size() << endl; 87 | 88 | // capacity 当前分配存储的容量 89 | cout << sv.capacity() << endl; 90 | 91 | // resize 改变容器中可存储元素的个数 92 | sv.resize(10); 93 | cout << sv.capacity() << endl; 94 | 95 | // shrink_to_fit 请求移除未使用的容量 96 | sv.shrink_to_fit(); 97 | cout << sv.capacity() << endl; 98 | 99 | // clear 从容器移除所有元素 100 | iv.clear(); 101 | printVector(iv); 102 | 103 | // insert:三种形式 104 | auto it = sv.begin(); 105 | it = sv.insert(it, "YES"); 106 | printVector(sv); 107 | 108 | sv.insert(it, 2, "NO"); 109 | printVector(sv); 110 | 111 | it = sv.begin(); 112 | vector sv5(2, "xx"); 113 | sv.insert(it+2, sv5.begin(), sv5.end()); 114 | printVector(sv); 115 | 116 | // erase 从容器移除指定的元素 117 | sv.erase(sv.begin()); 118 | printVector(sv); 119 | 120 | sv.erase(sv.begin() + 2, sv.begin() + 4); 121 | printVector(sv); 122 | 123 | // push_back 向容器尾部插入元素 124 | cout << sv.size() << endl; 125 | sv.push_back("add"); 126 | printVector(sv); 127 | 128 | // pop_back 移除容器的最末元素 129 | sv.pop_back(); 130 | printVector(sv); 131 | 132 | // swap 133 | sv.swap(sv5); 134 | printVector(sv); 135 | printVector(sv5); 136 | 137 | return 0; 138 | } 139 | 140 | -------------------------------------------------------------------------------- /SGI-STL Test/functor_test/README.md: -------------------------------------------------------------------------------- 1 | ## 仿函数(functor)-Code Test 2 | 3 | * [函数对象 function object](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/functor_test/functionObject.cpp) 4 | -------------------------------------------------------------------------------- /SGI-STL Test/functor_test/functionObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // 算法运算函数对象 9 | plus plusobj; 10 | minus minusobj; 11 | multiplies multipliesobj; 12 | divides dividesobj; 13 | modulus modulusobj; 14 | negate negateobj; 15 | 16 | cout << "Arithmetic function objects: " << endl; 17 | cout << plusobj(3, 5) << endl; 18 | cout << minusobj(3, 5) << endl; 19 | cout << multipliesobj(3, 5) << endl; 20 | cout << dividesobj(3, 5) << endl; 21 | cout << modulusobj(3, 5) << endl; 22 | cout << negateobj(3) << endl; 23 | 24 | // 以函数对象的临时对象履行函数功能 functor() 25 | cout << endl; 26 | cout << plus()(3, 5) << endl; 27 | cout << minus()(3, 5) << endl; 28 | cout << multiplies()(3, 5) << endl; 29 | cout << divides()(3, 5) << endl; 30 | cout << modulus()(3, 5) << endl; 31 | cout << negate()(3) << endl; 32 | 33 | // 关系运算函数对象 34 | equal_to equal_to_obj; 35 | not_equal_to not_equal_to_obj; 36 | greater greaterobj; 37 | greater_equal greater_equal_obj; 38 | less less_obj; 39 | less_equal less_equal_obj; 40 | 41 | cout << "Relational function objects: " << endl; 42 | cout << equal_to_obj(3, 5) << endl; 43 | cout << not_equal_to_obj(3, 5) << endl; 44 | cout << greaterobj(3, 5) << endl; 45 | cout << greater_equal_obj(3, 5) << endl; 46 | cout << less_obj(3, 5) << endl; 47 | cout << less_equal_obj(3, 5) << endl; 48 | 49 | // 以函数对象的临时对象履行函数功能 functor() 50 | cout << endl; 51 | cout << equal_to()(3, 5) << endl; 52 | cout << not_equal_to()(3, 5) << endl; 53 | cout << greater()(3, 5) << endl; 54 | cout << greater_equal()(3, 5) << endl; 55 | cout << less()(3, 5) << endl; 56 | cout << less_equal()(3, 5) << endl; 57 | 58 | // 逻辑运算函数对象 59 | logical_and and_obj; 60 | logical_or or_obj; 61 | logical_not not_obj; 62 | 63 | cout << "Logical function objects: " << endl; 64 | cout << and_obj(true, false) << endl; 65 | cout << or_obj(true, false) << endl; 66 | cout << not_obj(false) << endl; 67 | 68 | // 以函数对象的临时对象履行函数功能 functor() 69 | cout << endl; 70 | cout << logical_and()(true, false) << endl; 71 | cout << logical_or()(true, false) << endl; 72 | cout << logical_not()(false) << endl; 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /SGI-STL Test/iterator_test/README.md: -------------------------------------------------------------------------------- 1 | ## 迭代器(iterator)-Code Test 2 | 3 | * [find](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/iterator_test/find) 4 | * [iterator_traits_reverse](https://github.com/steveLauwh/SGI-STL/tree/master/SGI-STL%20Test/iterator_test/iterator_traits_reverse) 5 | -------------------------------------------------------------------------------- /SGI-STL Test/iterator_test/find/find.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 12 | 13 | const int arrSize = sizeof(arr) / sizeof(arr[0]); 14 | 15 | // vector 容器 16 | vector ivect(arr, arr + arrSize); 17 | 18 | // list 容器 19 | list ilist(arr, arr + arrSize); 20 | 21 | // deque 容器 22 | deque ideque(arr, arr + arrSize); 23 | 24 | /*** 25 | * 通过不同的迭代器,算法 find 对不同的容器进行查找操作 26 | */ 27 | vector::iterator itv = find(ivect.begin(), ivect.end(), 4); 28 | if (itv == ivect.end()) { 29 | cout << " The value 4 not found in the vector" << endl; 30 | } else { 31 | cout << " The value 4 found in the vector -> " << *itv << endl; 32 | } 33 | 34 | list::iterator itl = find(ilist.begin(), ilist.end(), 5); 35 | if (itl == ilist.end()) { 36 | cout << " The value 5 not found in the list" << endl; 37 | } else { 38 | cout << " The value 5 found in the list -> " << *itl << endl; 39 | } 40 | 41 | deque::iterator itd = find(ideque.begin(), ideque.end(), 6); 42 | if (itd == ideque.end()) { 43 | cout << " The value 6 not found in the deque" << endl; 44 | } else { 45 | cout << " The value 6 found in the deque -> " << *itd << endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /SGI-STL Test/iterator_test/iterator_traits_reverse/iterator_traits_reverse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | template 9 | void myReverse(T first, T last) 10 | { 11 | typename iterator_traits::difference_type n = distance(first, last); 12 | 13 | --n; 14 | 15 | // 首尾交换 16 | while (n > 0) { 17 | typename iterator_traits::value_type temp = *first; 18 | *first++ = *--last; 19 | *last = temp; 20 | 21 | n -= 2; 22 | } 23 | } 24 | 25 | int main(int argc, char *argv[]) 26 | { 27 | vector v{1, 2, 3, 4, 5, 6}; 28 | myReverse(v.begin(), v.end()); 29 | for (auto n : v) { 30 | cout << n << " "; 31 | } 32 | 33 | cout << endl; 34 | 35 | 36 | list l{1, 2, 3, 4, 5, 6}; 37 | myReverse(l.begin(), l.end()); 38 | for (auto n : v) { 39 | cout << n << " "; 40 | } 41 | 42 | cout << endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /SGI-STL V3.3/algobase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * Copyright (c) 1996,1997 15 | * Silicon Graphics Computer Systems, Inc. 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Silicon Graphics makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | */ 25 | 26 | #ifndef __SGI_STL_ALGOBASE_H 27 | #define __SGI_STL_ALGOBASE_H 28 | 29 | #ifndef __SGI_STL_PAIR_H 30 | #include 31 | #endif 32 | #ifndef __SGI_STL_ITERATOR_H 33 | #include 34 | #endif 35 | #ifndef __SGI_STL_INTERNAL_ALGOBASE_H 36 | #include 37 | #endif 38 | #ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H 39 | #include 40 | #endif 41 | 42 | #ifdef __STL_USE_NAMESPACES 43 | 44 | // Names from stl_algobase.h 45 | using __STD::iter_swap; 46 | using __STD::swap; 47 | using __STD::min; 48 | using __STD::max; 49 | using __STD::copy; 50 | using __STD::copy_backward; 51 | using __STD::copy_n; 52 | using __STD::fill; 53 | using __STD::fill_n; 54 | using __STD::mismatch; 55 | using __STD::equal; 56 | using __STD::lexicographical_compare; 57 | using __STD::lexicographical_compare_3way; 58 | 59 | // Names from stl_uninitialized.h 60 | using __STD::uninitialized_copy; 61 | using __STD::uninitialized_copy_n; 62 | using __STD::uninitialized_fill; 63 | using __STD::uninitialized_fill_n; 64 | 65 | #endif /* __STL_USE_NAMESPACES */ 66 | 67 | #endif /* __SGI_STL_ALGOBASE_H */ 68 | 69 | // Local Variables: 70 | // mode:C++ 71 | // End: 72 | -------------------------------------------------------------------------------- /SGI-STL V3.3/algorithm: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_ALGORITHM 28 | #define __SGI_STL_ALGORITHM 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_ALGORITHM */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996-1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_ALLOC_H 15 | #define __SGI_STL_ALLOC_H 16 | 17 | #ifndef __STL_CONFIG_H 18 | #include 19 | #endif 20 | #ifndef __SGI_STL_INTERNAL_ALLOC_H 21 | #include 22 | #endif 23 | 24 | #ifdef __STL_USE_NAMESPACES 25 | 26 | using __STD::__malloc_alloc_template; 27 | using __STD::malloc_alloc; 28 | using __STD::simple_alloc; 29 | using __STD::debug_alloc; 30 | using __STD::__default_alloc_template; 31 | using __STD::alloc; 32 | using __STD::single_client_alloc; 33 | #ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG 34 | using __STD::__malloc_alloc_oom_handler; 35 | #endif /* __STL_STATIC_TEMPLATE_MEMBER_BUG */ 36 | #ifdef __STL_USE_STD_ALLOCATORS 37 | using __STD::allocator; 38 | #endif /* __STL_USE_STD_ALLOCATORS */ 39 | 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_ALLOC_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/bvector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_BVECTOR_H 28 | #define __SGI_STL_BVECTOR_H 29 | 30 | #include 31 | #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION 32 | #include 33 | #else 34 | #include 35 | #include 36 | #endif 37 | 38 | #include 39 | 40 | #ifdef __STL_USE_NAMESPACES 41 | 42 | using __STD::bit_vector; 43 | 44 | #endif /* __STL_USE_NAMESPACES */ 45 | 46 | #endif /* __SGI_STL_BVECTOR_H */ 47 | 48 | // Local Variables: 49 | // mode:C++ 50 | // End: 51 | 52 | 53 | -------------------------------------------------------------------------------- /SGI-STL V3.3/defalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | */ 15 | 16 | // Inclusion of this file is DEPRECATED. This is the original HP 17 | // default allocator. It is provided only for backward compatibility. 18 | // This file WILL BE REMOVED in a future release. 19 | // 20 | // DO NOT USE THIS FILE unless you have an old container implementation 21 | // that requires an allocator with the HP-style interface. 22 | // 23 | // Standard-conforming allocators have a very different interface. The 24 | // standard default allocator is declared in the header . 25 | 26 | #ifndef DEFALLOC_H 27 | #define DEFALLOC_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | 37 | template 38 | inline T* allocate(ptrdiff_t size, T*) { 39 | set_new_handler(0); 40 | T* tmp = (T*)(::operator new((size_t)(size * sizeof(T)))); 41 | if (tmp == 0) { 42 | cerr << "out of memory" << endl; 43 | exit(1); 44 | } 45 | return tmp; 46 | } 47 | 48 | 49 | template 50 | inline void deallocate(T* buffer) { 51 | ::operator delete(buffer); 52 | } 53 | 54 | template 55 | class allocator { 56 | public: 57 | typedef T value_type; 58 | typedef T* pointer; 59 | typedef const T* const_pointer; 60 | typedef T& reference; 61 | typedef const T& const_reference; 62 | typedef size_t size_type; 63 | typedef ptrdiff_t difference_type; 64 | pointer allocate(size_type n) { 65 | return ::allocate((difference_type)n, (pointer)0); 66 | } 67 | void deallocate(pointer p) { ::deallocate(p); } 68 | pointer address(reference x) { return (pointer)&x; } 69 | const_pointer const_address(const_reference x) { 70 | return (const_pointer)&x; 71 | } 72 | size_type init_page_size() { 73 | return max(size_type(1), size_type(4096/sizeof(T))); 74 | } 75 | size_type max_size() const { 76 | return max(size_type(1), size_type(UINT_MAX/sizeof(T))); 77 | } 78 | }; 79 | 80 | class allocator { 81 | public: 82 | typedef void* pointer; 83 | }; 84 | 85 | 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /SGI-STL V3.3/deque: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_DEQUE 28 | #define __SGI_STL_DEQUE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __SGI_STL_DEQUE */ 38 | 39 | // Local Variables: 40 | // mode:C++ 41 | // End: 42 | -------------------------------------------------------------------------------- /SGI-STL V3.3/deque.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_DEQUE_H 28 | #define __SGI_STL_DEQUE_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __STL_USE_NAMESPACES 36 | using __STD::deque; 37 | #endif /* __STL_USE_NAMESPACES */ 38 | 39 | #endif /* __SGI_STL_DEQUE_H */ 40 | 41 | // Local Variables: 42 | // mode:C++ 43 | // End: 44 | -------------------------------------------------------------------------------- /SGI-STL V3.3/functional: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __SGI_STL_FUNCTIONAL 16 | #define __SGI_STL_FUNCTIONAL 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #endif /* __SGI_STL_FUNCTIONAL */ 23 | 24 | // Local Variables: 25 | // mode:C++ 26 | // End: 27 | -------------------------------------------------------------------------------- /SGI-STL V3.3/hash_map: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_MAP 28 | #define __SGI_STL_HASH_MAP 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | 36 | #endif /* __SGI_STL_HASH_MAP */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/hash_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_MAP_H 28 | #define __SGI_STL_HASH_MAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::hash; 39 | using __STD::hashtable; 40 | using __STD::hash_map; 41 | using __STD::hash_multimap; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | 45 | #endif /* __SGI_STL_HASH_MAP_H */ 46 | 47 | // Local Variables: 48 | // mode:C++ 49 | // End: 50 | -------------------------------------------------------------------------------- /SGI-STL V3.3/hash_set: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_SET 28 | #define __SGI_STL_HASH_SET 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | 36 | #endif /* __SGI_STL_HASH_SET */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/hash_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_SET_H 28 | #define __SGI_STL_HASH_SET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::hash; 39 | using __STD::hashtable; 40 | using __STD::hash_set; 41 | using __STD::hash_multiset; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | #endif /* __SGI_STL_HASH_SET_H */ 45 | -------------------------------------------------------------------------------- /SGI-STL V3.3/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996,1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_HASHTABLE_H 32 | #define __SGI_STL_HASHTABLE_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __STL_USE_NAMESPACES 40 | using __STD::hash; 41 | using __STD::hashtable; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | #endif /* __SGI_STL_HASHTABLE_H */ 45 | 46 | // Local Variables: 47 | // mode:C++ 48 | // End: 49 | -------------------------------------------------------------------------------- /SGI-STL V3.3/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * Copyright (c) 1997 15 | * Silicon Graphics Computer Systems, Inc. 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Silicon Graphics makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | */ 25 | 26 | #ifndef __SGI_STL_HEAP_H 27 | #define __SGI_STL_HEAP_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __STL_USE_NAMESPACES 33 | 34 | using __STD::push_heap; 35 | using __STD::pop_heap; 36 | using __STD::make_heap; 37 | using __STD::sort_heap; 38 | 39 | #endif /* __STL_USE_NAMESPACES */ 40 | 41 | 42 | #endif /* __SGI_STL_HEAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/iterator: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_ITERATOR 28 | #define __SGI_STL_ITERATOR 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __STL_USE_NEW_IOSTREAMS 35 | #include 36 | #else /* __STL_USE_NEW_IOSTREAMS */ 37 | #include 38 | #endif /* __STL_USE_NEW_IOSTREAMS */ 39 | 40 | #include 41 | #include 42 | 43 | #endif /* __SGI_STL_ITERATOR */ 44 | 45 | // Local Variables: 46 | // mode:C++ 47 | // End: 48 | -------------------------------------------------------------------------------- /SGI-STL V3.3/iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_ITERATOR_H 28 | #define __SGI_STL_ITERATOR_H 29 | 30 | #ifndef __SGI_STL_FUNCTION_H 31 | #include 32 | #endif 33 | #include 34 | 35 | #ifdef __STL_USE_NEW_IOSTREAMS 36 | #include 37 | #else /* __STL_USE_NEW_IOSTREAMS */ 38 | #include 39 | #endif /* __STL_USE_NEW_IOSTREAMS */ 40 | 41 | #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_H 42 | #include 43 | #endif 44 | #ifndef __SGI_STL_INTERNAL_ITERATOR_H 45 | #include 46 | #endif 47 | #ifndef __TYPE_TRAITS_H 48 | #include 49 | #endif 50 | #ifndef __SGI_STL_INTERNAL_CONSTRUCT_H 51 | #include 52 | #endif 53 | #ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 54 | #include 55 | #endif 56 | 57 | #ifdef __STL_USE_NAMESPACES 58 | 59 | // Names from stl_iterator.h 60 | 61 | using __STD::input_iterator_tag; 62 | using __STD::output_iterator_tag; 63 | using __STD::forward_iterator_tag; 64 | using __STD::bidirectional_iterator_tag; 65 | using __STD::random_access_iterator_tag; 66 | 67 | #if 0 68 | using __STD::iterator; 69 | #endif 70 | using __STD::input_iterator; 71 | using __STD::output_iterator; 72 | using __STD::forward_iterator; 73 | using __STD::bidirectional_iterator; 74 | using __STD::random_access_iterator; 75 | 76 | #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION 77 | using __STD::iterator_traits; 78 | #endif 79 | 80 | using __STD::iterator_category; 81 | using __STD::distance_type; 82 | using __STD::value_type; 83 | 84 | using __STD::distance; 85 | using __STD::advance; 86 | 87 | using __STD::insert_iterator; 88 | using __STD::front_insert_iterator; 89 | using __STD::back_insert_iterator; 90 | using __STD::inserter; 91 | using __STD::front_inserter; 92 | using __STD::back_inserter; 93 | 94 | using __STD::reverse_iterator; 95 | using __STD::reverse_bidirectional_iterator; 96 | 97 | using __STD::istream_iterator; 98 | using __STD::ostream_iterator; 99 | 100 | // Names from stl_construct.h 101 | using __STD::construct; 102 | using __STD::destroy; 103 | 104 | // Names from stl_raw_storage_iter.h 105 | using __STD::raw_storage_iterator; 106 | 107 | #endif /* __STL_USE_NAMESPACES */ 108 | 109 | #endif /* __SGI_STL_ITERATOR_H */ 110 | 111 | // Local Variables: 112 | // mode:C++ 113 | // End: 114 | -------------------------------------------------------------------------------- /SGI-STL V3.3/list: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_LIST 28 | #define __SGI_STL_LIST 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_LIST */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_LIST_H 28 | #define __SGI_STL_LIST_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __STL_USE_NAMESPACES 35 | using __STD::list; 36 | #endif /* __STL_USE_NAMESPACES */ 37 | 38 | #endif /* __SGI_STL_LIST_H */ 39 | 40 | // Local Variables: 41 | // mode:C++ 42 | // End: 43 | -------------------------------------------------------------------------------- /SGI-STL V3.3/map: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MAP 28 | #define __SGI_STL_MAP 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_MAP */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MAP_H 28 | #define __SGI_STL_MAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::map; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/multimap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MULTIMAP_H 28 | #define __SGI_STL_MULTIMAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::multimap; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MULTIMAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/multiset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MULTISET_H 28 | #define __SGI_STL_MULTISET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::multiset; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MULTISET_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/numeric: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_NUMERIC 28 | #define __SGI_STL_NUMERIC 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __STL_USE_NEW_IOSTREAMS 35 | #include 36 | #else /* __STL_USE_NEW_IOSTREAMS */ 37 | #include 38 | #endif /* __STL_USE_NEW_IOSTREAMS */ 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #endif /* __SGI_STL_NUMERIC */ 46 | 47 | // Local Variables: 48 | // mode:C++ 49 | // End: 50 | -------------------------------------------------------------------------------- /SGI-STL V3.3/pair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_PAIR_H 28 | #define __SGI_STL_PAIR_H 29 | 30 | #ifndef __STL_CONFIG_H 31 | #include 32 | #endif 33 | #ifndef __SGI_STL_INTERNAL_RELOPS 34 | #include 35 | #endif 36 | #ifndef __SGI_STL_INTERNAL_PAIR_H 37 | #include 38 | #endif 39 | 40 | #ifdef __STL_USE_NAMESPACES 41 | 42 | using __STD::pair; 43 | using __STD::make_pair; 44 | 45 | #endif /* __STL_USE_NAMESPACES */ 46 | 47 | #endif /* __SGI_STL_PAIR_H */ 48 | 49 | // Local Variables: 50 | // mode:C++ 51 | // End: 52 | -------------------------------------------------------------------------------- /SGI-STL V3.3/pthread_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996-1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_PTHREAD_ALLOC_H 15 | #define __SGI_STL_PTHREAD_ALLOC_H 16 | 17 | #include 18 | 19 | #ifdef __STL_USE_NAMESPACES 20 | 21 | using __STD::_Pthread_alloc_template; 22 | using __STD::pthread_alloc; 23 | 24 | #endif /* __STL_USE_NAMESPACES */ 25 | 26 | 27 | #endif /* __SGI_STL_PTHREAD_ALLOC_H */ 28 | 29 | // Local Variables: 30 | // mode:C++ 31 | // End: 32 | -------------------------------------------------------------------------------- /SGI-STL V3.3/queue: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_QUEUE 28 | #define __SGI_STL_QUEUE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #endif /* __SGI_STL_QUEUE */ 42 | 43 | // Local Variables: 44 | // mode:C++ 45 | // End: 46 | -------------------------------------------------------------------------------- /SGI-STL V3.3/rope: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_ROPE 15 | #define __SGI_STL_ROPE 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #endif /* __SGI_STL_ROPE */ 29 | 30 | // Local Variables: 31 | // mode:C++ 32 | // End: 33 | -------------------------------------------------------------------------------- /SGI-STL V3.3/rope.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_ROPE_H 15 | #define __SGI_STL_ROPE_H 16 | 17 | #include 18 | #include 19 | 20 | #ifdef __STL_USE_NAMESPACES 21 | 22 | using __STD::char_producer; 23 | using __STD::sequence_buffer; 24 | using __STD::rope; 25 | using __STD::crope; 26 | using __STD::wrope; 27 | 28 | #endif /* __STL_USE_NAMESPACES */ 29 | 30 | #endif /* __SGI_STL_ROPE_H */ 31 | 32 | // Local Variables: 33 | // mode:C++ 34 | // End: 35 | -------------------------------------------------------------------------------- /SGI-STL V3.3/set: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_SET 28 | #define __SGI_STL_SET 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_SET */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_SET_H 28 | #define __SGI_STL_SET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::set; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_SET_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/slist: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __SGI_STL_SLIST 16 | #define __SGI_STL_SLIST 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif /* __SGI_STL_SLIST */ 25 | 26 | // Local Variables: 27 | // mode:C++ 28 | // End: 29 | -------------------------------------------------------------------------------- /SGI-STL V3.3/slist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __SGI_STL_SLIST_H 16 | #define __SGI_STL_SLIST_H 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #ifdef __STL_USE_NAMESPACES 23 | using __STD::slist; 24 | #endif /* __STL_USE_NAMESPACES */ 25 | 26 | #endif /* __SGI_STL_SLIST_H */ 27 | 28 | // Local Variables: 29 | // mode:C++ 30 | // End: 31 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stack: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_STACK 28 | #define __SGI_STL_STACK 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __SGI_STL_STACK */ 38 | 39 | // Local Variables: 40 | // mode:C++ 41 | // End: 42 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_STACK_H 28 | #define __SGI_STL_STACK_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef __STL_USE_NAMESPACES 37 | using __STD::stack; 38 | using __STD::queue; 39 | using __STD::priority_queue; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_STACK_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stdexcept: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STDEXCEPT 15 | #define __SGI_STDEXCEPT 16 | 17 | #include 18 | 19 | #if defined(__STL_USE_EXCEPTIONS) || \ 20 | !(defined(_MIPS_SIM) && defined(_ABIO32) && _MIPS_SIM == _ABIO32) 21 | 22 | #include 23 | 24 | __STL_BEGIN_NAMESPACE 25 | 26 | class __Named_exception : public __STL_EXCEPTION_BASE { 27 | public: 28 | __Named_exception(const string& __str) { 29 | strncpy(_M_name, __get_c_string(__str), _S_bufsize); 30 | _M_name[_S_bufsize - 1] = '\0'; 31 | } 32 | virtual const char* what() const __STL_NOTHROW { return _M_name; } 33 | 34 | private: 35 | enum { _S_bufsize = 256 }; 36 | char _M_name[_S_bufsize]; 37 | }; 38 | 39 | class logic_error : public __Named_exception { 40 | public: 41 | logic_error(const string& __s) : __Named_exception(__s) {} 42 | }; 43 | 44 | class runtime_error : public __Named_exception { 45 | public: 46 | runtime_error(const string& __s) : __Named_exception(__s) {} 47 | }; 48 | 49 | class domain_error : public logic_error { 50 | public: 51 | domain_error(const string& __arg) : logic_error(__arg) {} 52 | }; 53 | 54 | class invalid_argument : public logic_error { 55 | public: 56 | invalid_argument(const string& __arg) : logic_error(__arg) {} 57 | }; 58 | 59 | class length_error : public logic_error { 60 | public: 61 | length_error(const string& __arg) : logic_error(__arg) {} 62 | }; 63 | 64 | class out_of_range : public logic_error { 65 | public: 66 | out_of_range(const string& __arg) : logic_error(__arg) {} 67 | }; 68 | 69 | class range_error : public runtime_error { 70 | public: 71 | range_error(const string& __arg) : runtime_error(__arg) {} 72 | }; 73 | 74 | class overflow_error : public runtime_error { 75 | public: 76 | overflow_error(const string& __arg) : runtime_error(__arg) {} 77 | }; 78 | 79 | class underflow_error : public runtime_error { 80 | public: 81 | underflow_error(const string& __arg) : runtime_error(__arg) {} 82 | }; 83 | 84 | __STL_END_NAMESPACE 85 | 86 | #ifndef __SGI_STL_STRING 87 | #include 88 | #endif 89 | 90 | #endif /* Not o32, and no exceptions */ 91 | 92 | #endif /* __SGI_STDEXCEPT */ 93 | 94 | // Local Variables: 95 | // mode:C++ 96 | // End: 97 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_ctraits_fns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | // WARNING: This is an internal header file, included by other C++ 15 | // standard library headers. You should not attempt to use this header 16 | // file directly. 17 | 18 | #ifndef __SGI_STL_INTERNAL_CTRAITS_FUNCTIONS_H 19 | #define __SGI_STL_INTERNAL_CTRAITS_FUNCTIONS_H 20 | 21 | // This file contains a few small adapters that allow a character 22 | // traits class to be used as a function object. 23 | 24 | __STL_BEGIN_NAMESPACE 25 | 26 | template 27 | struct _Eq_traits 28 | : public binary_function 31 | { 32 | bool operator()(const typename _Traits::char_type& __x, 33 | const typename _Traits::char_type& __y) const 34 | { return _Traits::eq(__x, __y); } 35 | }; 36 | 37 | template 38 | struct _Eq_int_traits 39 | : public binary_function 42 | { 43 | bool operator()(const typename _Traits::char_type& __x, 44 | const typename _Traits::int_type& __y) const 45 | { return _Traits::eq_int_type(_Traits::to_int_type(__x), __y); } 46 | }; 47 | 48 | template 49 | struct _Lt_traits 50 | : public binary_function 53 | { 54 | bool operator()(const typename _Traits::char_type& __x, 55 | const typename _Traits::char_type& __y) const 56 | { return _Traits::lt(__x, __y); } 57 | }; 58 | 59 | __STL_END_NAMESPACE 60 | 61 | #endif /* __SGI_STL_INTERNAL_CTRAITS_FUNCTIONS_H */ 62 | 63 | // Local Variables: 64 | // mode:C++ 65 | // End: 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1998 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_EXCEPTION_H 15 | #define __SGI_STL_EXCEPTION_H 16 | 17 | // This header exists solely for portability. Normally it just includes 18 | // the header . 19 | 20 | // The header contains low-level functions that interact 21 | // with a compiler's exception-handling mechanism. It is assumed to 22 | // be supplied with the compiler, rather than with the library, because 23 | // it is inherently tied very closely to the compiler itself. 24 | 25 | // On platforms where does not exist, this header defines 26 | // an exception base class. This is *not* a substitute for everything 27 | // in , but it suffices to support a bare minimum of STL 28 | // functionality. 29 | 30 | #include 31 | 32 | #ifndef __STL_NO_EXCEPTION_HEADER 33 | 34 | #include 35 | #define __STL_EXCEPTION_BASE exception 36 | 37 | #else /* __STL_NO_EXCEPTION_HEADER */ 38 | 39 | __STL_BEGIN_NAMESPACE 40 | 41 | class _Exception { 42 | public: 43 | virtual ~_Exception() __STL_NOTHROW {} 44 | virtual const char* what() const __STL_NOTHROW { return ""; } 45 | }; 46 | 47 | #define __STL_EXCEPTION_BASE _Exception 48 | 49 | __STL_END_NAMESPACE 50 | 51 | #endif /* __STL_NO_EXCEPTION_HEADER */ 52 | 53 | #endif /* __SGI_STL_EXCEPTION_H */ 54 | 55 | // Local Variables: 56 | // mode:C++ 57 | // End: 58 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_hash_fun.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996-1998 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_HASH_FUN_H 32 | #define __SGI_STL_HASH_FUN_H 33 | 34 | #include 35 | 36 | __STL_BEGIN_NAMESPACE 37 | 38 | template struct hash { }; 39 | 40 | inline size_t __stl_hash_string(const char* __s) 41 | { 42 | unsigned long __h = 0; 43 | for ( ; *__s; ++__s) 44 | __h = 5*__h + *__s; 45 | 46 | return size_t(__h); 47 | } 48 | 49 | __STL_TEMPLATE_NULL struct hash 50 | { 51 | size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 52 | }; 53 | 54 | __STL_TEMPLATE_NULL struct hash 55 | { 56 | size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 57 | }; 58 | 59 | __STL_TEMPLATE_NULL struct hash { 60 | size_t operator()(char __x) const { return __x; } 61 | }; 62 | __STL_TEMPLATE_NULL struct hash { 63 | size_t operator()(unsigned char __x) const { return __x; } 64 | }; 65 | __STL_TEMPLATE_NULL struct hash { 66 | size_t operator()(unsigned char __x) const { return __x; } 67 | }; 68 | __STL_TEMPLATE_NULL struct hash { 69 | size_t operator()(short __x) const { return __x; } 70 | }; 71 | __STL_TEMPLATE_NULL struct hash { 72 | size_t operator()(unsigned short __x) const { return __x; } 73 | }; 74 | __STL_TEMPLATE_NULL struct hash { 75 | size_t operator()(int __x) const { return __x; } 76 | }; 77 | __STL_TEMPLATE_NULL struct hash { 78 | size_t operator()(unsigned int __x) const { return __x; } 79 | }; 80 | __STL_TEMPLATE_NULL struct hash { 81 | size_t operator()(long __x) const { return __x; } 82 | }; 83 | __STL_TEMPLATE_NULL struct hash { 84 | size_t operator()(unsigned long __x) const { return __x; } 85 | }; 86 | 87 | __STL_END_NAMESPACE 88 | 89 | #endif /* __SGI_STL_HASH_FUN_H */ 90 | 91 | // Local Variables: 92 | // mode:C++ 93 | // End: 94 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_pair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_INTERNAL_PAIR_H 32 | #define __SGI_STL_INTERNAL_PAIR_H 33 | 34 | __STL_BEGIN_NAMESPACE 35 | 36 | template 37 | struct pair { 38 | typedef _T1 first_type; 39 | typedef _T2 second_type; 40 | 41 | _T1 first; 42 | _T2 second; 43 | pair() : first(_T1()), second(_T2()) {} 44 | pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {} 45 | 46 | #ifdef __STL_MEMBER_TEMPLATES 47 | template 48 | pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} 49 | #endif 50 | }; 51 | 52 | template 53 | inline bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 54 | { 55 | return __x.first == __y.first && __x.second == __y.second; 56 | } 57 | 58 | template 59 | inline bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) 60 | { 61 | return __x.first < __y.first || 62 | (!(__y.first < __x.first) && __x.second < __y.second); 63 | } 64 | 65 | #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER 66 | 67 | template 68 | inline bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { 69 | return !(__x == __y); 70 | } 71 | 72 | template 73 | inline bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { 74 | return __y < __x; 75 | } 76 | 77 | template 78 | inline bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { 79 | return !(__y < __x); 80 | } 81 | 82 | template 83 | inline bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { 84 | return !(__x < __y); 85 | } 86 | 87 | #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */ 88 | 89 | template 90 | inline pair<_T1, _T2> make_pair(const _T1& __x, const _T2& __y) 91 | { 92 | return pair<_T1, _T2>(__x, __y); 93 | } 94 | 95 | __STL_END_NAMESPACE 96 | 97 | #endif /* __SGI_STL_INTERNAL_PAIR_H */ 98 | 99 | // Local Variables: 100 | // mode:C++ 101 | // End: 102 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_range_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 3 | * Silicon Graphics 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __STL_RANGE_ERRORS_H 16 | #define __STL_RANGE_ERRORS_H 17 | 18 | // A few places in the STL throw range errors, using standard exception 19 | // classes defined in . This header file provides functions 20 | // to throw those exception objects. 21 | 22 | // __STL_DONT_THROW_RANGE_ERRORS is a hook so that users can disable 23 | // this exception throwing. 24 | 25 | #include 26 | 27 | #if defined(__STL_CAN_THROW_RANGE_ERRORS) && \ 28 | defined(__STL_USE_EXCEPTIONS) && \ 29 | !defined(__STL_DONT_THROW_RANGE_ERRORS) 30 | # define __STL_THROW_RANGE_ERRORS 31 | #endif 32 | 33 | // For the SGI 7.3 compiler, declare these functions here and define them 34 | // elsewhere. 35 | #if defined(__STL_THROW_RANGE_ERRORS) && \ 36 | defined(__sgi) && !defined(__GNUC__) && \ 37 | _COMPILER_VERSION >= 730 && defined(_STANDARD_C_PLUS_PLUS) 38 | 39 | __STL_BEGIN_NAMESPACE 40 | void __stl_throw_range_error(const char* __msg); 41 | void __stl_throw_length_error(const char* __msg); 42 | __STL_END_NAMESPACE 43 | 44 | // For other compilers where we're throwing range errors, include the 45 | // stdexcept header and throw the appropriate exceptions directly. 46 | #elif defined(__STL_THROW_RANGE_ERRORS) 47 | 48 | #include 49 | 50 | __STL_BEGIN_NAMESPACE 51 | inline void __stl_throw_range_error(const char* __msg) 52 | { throw range_error(__msg); } 53 | inline void __stl_throw_length_error(const char* __msg) 54 | { throw length_error(__msg); } 55 | __STL_END_NAMESPACE 56 | 57 | // Otherwise, define inline functions that do nothing. 58 | #else 59 | 60 | __STL_BEGIN_NAMESPACE 61 | inline void __stl_throw_range_error(const char*) {} 62 | inline void __stl_throw_length_error(const char*) {} 63 | __STL_END_NAMESPACE 64 | 65 | #endif 66 | 67 | #endif /* __STL_RANGE_ERRORS_H */ 68 | 69 | // Local Variables: 70 | // mode:C++ 71 | // End: 72 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_raw_storage_iter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 32 | #define __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 33 | 34 | __STL_BEGIN_NAMESPACE 35 | 36 | template 37 | class raw_storage_iterator { 38 | protected: 39 | _ForwardIterator _M_iter; 40 | public: 41 | typedef output_iterator_tag iterator_category; 42 | typedef void value_type; 43 | typedef void difference_type; 44 | typedef void pointer; 45 | typedef void reference; 46 | 47 | explicit raw_storage_iterator(_ForwardIterator __x) : _M_iter(__x) {} 48 | raw_storage_iterator& operator*() { return *this; } 49 | raw_storage_iterator& operator=(const _Tp& __element) { 50 | construct(&*_M_iter, __element); 51 | return *this; 52 | } 53 | raw_storage_iterator<_ForwardIterator, _Tp>& operator++() { 54 | ++_M_iter; 55 | return *this; 56 | } 57 | raw_storage_iterator<_ForwardIterator, _Tp> operator++(int) { 58 | raw_storage_iterator<_ForwardIterator, _Tp> __tmp = *this; 59 | ++_M_iter; 60 | return __tmp; 61 | } 62 | }; 63 | 64 | #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION 65 | 66 | template 67 | inline output_iterator_tag 68 | iterator_category(const raw_storage_iterator<_ForwardIterator, _Tp>&) 69 | { 70 | return output_iterator_tag(); 71 | } 72 | 73 | #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ 74 | 75 | __STL_END_NAMESPACE 76 | 77 | #endif /* __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H */ 78 | 79 | // Local Variables: 80 | // mode:C++ 81 | // End: 82 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_relops.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * Copyright (c) 1996,1997 15 | * Silicon Graphics 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Silicon Graphics makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_INTERNAL_RELOPS 32 | #define __SGI_STL_INTERNAL_RELOPS 33 | 34 | __STL_BEGIN_RELOPS_NAMESPACE 35 | 36 | template 37 | inline bool operator!=(const _Tp& __x, const _Tp& __y) { 38 | return !(__x == __y); 39 | } 40 | 41 | template 42 | inline bool operator>(const _Tp& __x, const _Tp& __y) { 43 | return __y < __x; 44 | } 45 | 46 | template 47 | inline bool operator<=(const _Tp& __x, const _Tp& __y) { 48 | return !(__y < __x); 49 | } 50 | 51 | template 52 | inline bool operator>=(const _Tp& __x, const _Tp& __y) { 53 | return !(__x < __y); 54 | } 55 | 56 | __STL_END_RELOPS_NAMESPACE 57 | 58 | #endif /* __SGI_STL_INTERNAL_RELOPS */ 59 | 60 | // Local Variables: 61 | // mode:C++ 62 | // End: 63 | -------------------------------------------------------------------------------- /SGI-STL V3.3/stl_string_fwd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_STRING_FWD_H 15 | #define __SGI_STL_STRING_FWD_H 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | __STL_BEGIN_NAMESPACE 23 | 24 | template , 26 | class _Alloc = __STL_DEFAULT_ALLOCATOR(_CharT) > 27 | class basic_string; 28 | 29 | typedef basic_string string; 30 | typedef basic_string wstring; 31 | 32 | static const char* __get_c_string(const string&); 33 | 34 | __STL_END_NAMESPACE 35 | 36 | #endif /* __SGI_STL_STRING_FWD_H */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /SGI-STL V3.3/tempbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_TEMPBUF_H 28 | #define __SGI_STL_TEMPBUF_H 29 | 30 | #ifndef __SGI_STL_PAIR_H 31 | #include 32 | #endif 33 | #include /* XXX should use */ 34 | #include /* XXX should use */ 35 | #include /* XXX should use */ 36 | #ifndef __TYPE_TRAITS_H 37 | #include 38 | #endif 39 | #ifndef __SGI_STL_INTERNAL_CONSTRUCT_H 40 | #include 41 | #endif 42 | #ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H 43 | #include 44 | #endif 45 | #ifndef __SGI_STL_INTERNAL_TEMPBUF_H 46 | #include 47 | #endif 48 | 49 | #ifdef __STL_USE_NAMESPACES 50 | 51 | using __STD::get_temporary_buffer; 52 | using __STD::return_temporary_buffer; 53 | using __STD::temporary_buffer; 54 | 55 | #endif /* __STL_USE_NAMESPACES */ 56 | 57 | #endif /* __SGI_STL_TEMPBUF_H */ 58 | 59 | // Local Variables: 60 | // mode:C++ 61 | // End: 62 | -------------------------------------------------------------------------------- /SGI-STL V3.3/tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1996,1997 4 | * Silicon Graphics Computer Systems, Inc. 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Silicon Graphics makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1994 16 | * Hewlett-Packard Company 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Hewlett-Packard Company makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | * 26 | * 27 | */ 28 | 29 | #ifndef __SGI_STL_TREE_H 30 | #define __SGI_STL_TREE_H 31 | 32 | #ifndef __SGI_STL_INTERNAL_TREE_H 33 | #include 34 | #endif 35 | #include 36 | #include 37 | 38 | #ifdef __STL_USE_NAMESPACES 39 | using __STD::rb_tree; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_TREE_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /SGI-STL V3.3/utility: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_UTILITY 28 | #define __SGI_STL_UTILITY 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #endif /* __SGI_STL_UTILITY */ 35 | 36 | // Local Variables: 37 | // mode:C++ 38 | // End: 39 | -------------------------------------------------------------------------------- /SGI-STL V3.3/vector: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_VECTOR 28 | #define __SGI_STL_VECTOR 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif /* __SGI_STL_VECTOR */ 39 | 40 | // Local Variables: 41 | // mode:C++ 42 | // End: 43 | -------------------------------------------------------------------------------- /SGI-STL V3.3/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_VECTOR_H 28 | #define __SGI_STL_VECTOR_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __STL_USE_NAMESPACES 36 | using __STD::vector; 37 | #endif /* __STL_USE_NAMESPACES */ 38 | 39 | #endif /* __SGI_STL_VECTOR_H */ 40 | 41 | // Local Variables: 42 | // mode:C++ 43 | // End: 44 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/RBTree.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/RBTree.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/README.md: -------------------------------------------------------------------------------- 1 | ## Other 2 | 3 | 包含 STL 六大组件之外的内容,如环境配置文件(stl_config.h)。 4 | 5 | ## 环境配置 stl_config.h 6 | 7 | * __STL_STATIC_TEMPLATE_MEMBER_BUG 模板类拥有静态数据成员 8 | 9 | 为静态数据成员进行定义,并设初始值。 10 | ```cpp 11 | template 12 | class testClass { 13 | public: 14 | static int _data; 15 | }; 16 | template<> int testClass::_data = 1; 17 | template<> int testClass::_data = 2; 18 | ``` 19 | ## 临时对象的产生与作用 20 | 21 | 临时对象就是一种无名对象。它的出现如果不在程序员的预期之下,往往造成效率上的负担。 22 | 23 | 刻意制造临时对象的方法是在类型名称后加一对小括号,并可指定初值,例如 Shape(3, 5) 或 int(8),其意义相当于调用相应的 constructor 且不指定对象名称。 24 | 25 | ```cpp 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | // 仿函数或函数对象 33 | template 34 | class print 35 | { 36 | public: 37 | void operator() (const T& elem) 38 | { 39 | cout << elem << ' '; 40 | } 41 | }; 42 | 43 | int main() 44 | { 45 | int ia[6] = {0, 1, 2, 3, 4, 5}; 46 | vector iv(ia, ia+6); 47 | 48 |    // print() 是一个临时对象,不是一个函数调用操作 49 |    for_each(iv.begin(), iv.end(), print()); 50 | } 51 | ``` 52 | 53 | ## 静态常量整数成员在 class 内部直接初始化 54 | 55 | 在 class 内含 const static integral data member,那么根据 C++ 标准规格,可以在 class 之内直接给予初值。所谓 integral 泛指所有整数类型,不单只是指 int。 56 | 57 | ```cpp 58 | template 59 | class testClass 60 | { 61 | public: 62 | static const int _datai = 5; 63 | static const long _datal = 3L; 64 | static const char _datac = 'c'; 65 | }; 66 | ``` 67 | 68 | ## increment / decrement /derefrence 操作符 69 | 70 | increment/derefrence 操作符在迭代器的实现占有很重要地位。 71 | 72 | ```cpp 73 | class INT 74 | { 75 | public: 76 | INT(int i) : m_i(i) {}; 77 | 78 |    INT& operator++() { 79 | ++(this->m_i); 80 | return *this; 81 | } 82 | 83 | const INT operator++(int) { 84 | INT temp = *this; 85 | ++(*this); 86 | return temp; 87 | } 88 | 89 |    INT& operator--() { 90 |        --(this->m_i); 91 | return *this; 92 |    } 93 | 94 | const INT operator--(int) { 95 | INT temp = *this; 96 | --(*this); 97 | return temp; 98 | } 99 | 100 |    int& operator*() const { 101 |        return (int&)m_i; 102 |    } 103 | 104 | private: 105 | int m_i; 106 | }; 107 | ``` 108 | 109 | ## 前闭后开区间表示法 [) 110 | 111 | 任何一个 STL 算法,都需要获得一对迭代器所标示的区间,该区间为前闭后开区间,以 [first, last) 表示。 112 | 113 | 整个实际范围从 first 开始,直到 last-1。 114 | 115 | ## Function call 操作符(operator()) 116 | 117 | C语言中,函数指针的缺点:无法持有自己的状态,也无法达到组件技术中的可适配性。 118 | 119 | 仿函数:使用起来就像函数一样的东西。如果针对某个 class 进行 operator() 重载,它就成为一个仿函数。 120 | 121 | ```cpp 122 | #include 123 | using namespace std; 124 | 125 | template 126 | struct plus { 127 |    T operator() (const T& x, const T& y) const { 128 | return x + y; 129 | } 130 | }; 131 | 132 | template 133 | struct minus { 134 |    T operator() (const T& x, const T& y) const { 135 | return x - y; 136 | } 137 | }; 138 | 139 | int main() 140 | { 141 |    // 以下产生仿函数对象 142 | plus plusobj; 143 | minus minusobj; 144 | 145 |    cout << plusobj(3, 5) << endl; 146 |    cout << minusobj(3, 5) << endl; 147 | 148 |    // 仿函数的临时对象 149 |    cout << plus()(43, 50) << endl; 150 | cout << minus()(43, 50) << endl; 151 | 152 | return 0; 153 | } 154 | ``` 155 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/SGISTL.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/SGISTL.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/STLAlgorithm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/STLAlgorithm.png -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/adapter.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/adapter.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/allocator.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/allocator.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/allocator_memorypool.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/allocator_memorypool.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/associativecontainer.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/associativecontainer.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/container.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/container.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/deque DS.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/deque DS.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/deque.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/deque.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/functionobject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/functionobject.png -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/iteratortraits.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/iteratortraits.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/list.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/list.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/queue.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/queue.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/sequencecontainer.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/sequencecontainer.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/stack.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/Other/vector.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steveLauwh/SGI-STL/be34aace923769ee114366e0e7decf8521d422b9/The Annotated STL Sources V3.3/Other/vector.PNG -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/README.md: -------------------------------------------------------------------------------- 1 | ## STL 六大组件 2 | 3 | 「STL 六大组件的交互关系」 4 | * [Container](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/container) 通过 [Allocator](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/allocator) 取得数据储存空间 5 | * [Algorithm](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/algorithm) 通过 [Iterator](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/iterator) 存取 [Container](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/container) 内容 6 | * [Functor](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/functor-function%20object) 可以协助 [Algorithm](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/algorithm) 完成不同的策略变化 7 | * [Adapter](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/adapter) 可以修饰或套接 [Functor](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/functor-function%20object)、[Iterator](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/iterator)。 8 | 9 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/SGISTL.PNG) 10 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/adapter/README.md: -------------------------------------------------------------------------------- 1 | ## 适配器(adapter) 2 | 3 | 适配器:一种用来修饰容器、仿函数或迭代器接口的东西。例如,STL 提供的 queue 和 stack,虽然看似容器,其实只能算是一种容器适配器,因为它们的底部完全借助 deque,所有操作都由底层的 deque 供应。改变 functor 接口者,称为 function adapter等。 4 | 5 | 适配器(adapter) 在 STL 组件的灵活组合运用功能上,扮演者转换器的角色。 6 | 7 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/adapter.PNG) 8 | 9 | ### 应用于容器,container adapter 10 | 11 | STL 提供的两个容器 queue 和 stack,它们修饰 deque 的接口而形成的。 12 | 13 | ### 应用于迭代器,iterator adapter 14 | 15 | STL 提供了许多应用于迭代器的适配器。 16 | 17 | > insert iterator 18 | 19 | 插入迭代器内部都维护有一个容器,容器当然有自己的迭代器,当客户端对插入迭代器做赋值操作时,就在插入迭代器中被转为对该容器的迭代器做插入操作。 20 | 21 | `back_insert_iterator` 22 | 23 | 用于在容器尾部插入的迭代器适配器。 24 | 25 | `front_insert_iterator` 26 | 27 | 用于在容器头部插入的迭代器适配器。 28 | 29 | > reverse iterator 30 | 31 | 将迭代器的移动行为倒转。以尾到头的方向来处理序列中的元素。 32 | 33 | > stream iterator 34 | 35 | 将迭代器绑定到一个 stream 对象身上,绑定到 istream 对象为 istream_iterator,拥有输入能力。 36 | 37 | 绑定到 ostream 对象为 ostream_iterator,拥有输出能力。 38 | 39 | ### 应用于仿函数,function adapter 40 | 41 | > 对返回值进行逻辑否定:not1, not2 42 | 43 | > 对参数进行绑定:bind1st, bind2nd 44 | 45 | > 用于函数合成:compose1, compose2 46 | 47 | > 用于函数指针:ptr_fun 48 | 49 | > 用于成员函数指针:mem_fun, mem_fun_ref 50 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/algorithm/algobase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * Copyright (c) 1996,1997 15 | * Silicon Graphics Computer Systems, Inc. 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Silicon Graphics makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | */ 25 | 26 | #ifndef __SGI_STL_ALGOBASE_H 27 | #define __SGI_STL_ALGOBASE_H 28 | 29 | #ifndef __SGI_STL_PAIR_H 30 | #include 31 | #endif 32 | #ifndef __SGI_STL_ITERATOR_H 33 | #include 34 | #endif 35 | #ifndef __SGI_STL_INTERNAL_ALGOBASE_H 36 | #include 37 | #endif 38 | #ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H 39 | #include 40 | #endif 41 | 42 | #ifdef __STL_USE_NAMESPACES 43 | 44 | // Names from stl_algobase.h 45 | using __STD::iter_swap; 46 | using __STD::swap; 47 | using __STD::min; 48 | using __STD::max; 49 | using __STD::copy; 50 | using __STD::copy_backward; 51 | using __STD::copy_n; 52 | using __STD::fill; 53 | using __STD::fill_n; 54 | using __STD::mismatch; 55 | using __STD::equal; 56 | using __STD::lexicographical_compare; 57 | using __STD::lexicographical_compare_3way; 58 | 59 | // Names from stl_uninitialized.h 60 | using __STD::uninitialized_copy; 61 | using __STD::uninitialized_copy_n; 62 | using __STD::uninitialized_fill; 63 | using __STD::uninitialized_fill_n; 64 | 65 | #endif /* __STL_USE_NAMESPACES */ 66 | 67 | #endif /* __SGI_STL_ALGOBASE_H */ 68 | 69 | // Local Variables: 70 | // mode:C++ 71 | // End: 72 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/algorithm/algorithm: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_ALGORITHM 28 | #define __SGI_STL_ALGORITHM 29 | 30 | // 头文件 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __SGI_STL_ALGORITHM */ 38 | 39 | // Local Variables: 40 | // mode:C++ 41 | // End: 42 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/algorithm/numeric: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_NUMERIC 28 | #define __SGI_STL_NUMERIC 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __STL_USE_NEW_IOSTREAMS 35 | #include 36 | #else /* __STL_USE_NEW_IOSTREAMS */ 37 | #include 38 | #endif /* __STL_USE_NEW_IOSTREAMS */ 39 | 40 | // 头文件 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #endif /* __SGI_STL_NUMERIC */ 47 | 48 | // Local Variables: 49 | // mode:C++ 50 | // End: 51 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/allocator/README.md: -------------------------------------------------------------------------------- 1 | ## 配置器(allocator) 2 | 3 | 配置器:负责空间配置与管理,从实现的角度来看,配置器是一个实现了动态空间配置、空间管理、空间释放的 class template。 4 | 5 | 空间配置器:整个 STL 的操作对象(所有的数值)都存放在容器之内,而容器一定需要配置空间以存放内容。 6 | 7 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/allocator.PNG) 8 | 9 | ## 具有次配置力(sub-allocation)的 SGI 空间配置器 10 | 11 | ### SGI STL 空间配置器的结构 12 | 13 | SGI STL 的配置器,其名称是 alloc 而不是 allocator,而且不接受任何参数。 14 | 15 | SGI STL 的每一个容器都已经指定其缺省的空间配置器为 alloc。 16 | 17 | ```cpp 18 | template // 缺省使用 alloc 为配置器 19 | class vector {...}; 20 | 21 | vector iv; 22 | ``` 23 | 24 | * ----SGI 标准的空间配置器,std::allocator 25 | 26 | allocator 只是基层内存配置/释放行为(::operator::new 和 ::operator::delete)的一层薄薄的包装,并没有考虑到任何效率上的强化。 27 | 28 | * SGI 特殊的空间配置器,std::alloc 29 | 30 | + :定义了全局函数 construct() 和 destroy(),负责对象的构造和析构。 31 | + :定义了一、二级配置器,配置器名为 alloc。 32 | + :定义了全局函数,用来填充(fill)或复制(copy)大块内存数据。 33 | 34 | * 构造和析构基本工具 35 | 36 | 具体看 源码,功能是构造和析构操作。 37 | 38 | * 空间的配置和释放,std::alloc 39 | + 向 system heap 要求空间 40 | + 考虑多线程(multi-threads)状态 41 | + 考虑内存不足时的应变措施 42 | + 考虑过多 “小型区块” 可能造成的内存碎片问题 43 | 44 | 对象构造前的空间配置 和 对象析构后的空间释放,具体看 。 45 | 46 | ### SGI STL 空间配置器的分析 47 | 48 | 考虑到小型区块可能造成内存碎片问题,SGI 采用两级配置器,第一级配置器直接使用 malloc() 和 free() 实现;第二级配置器使用 memory pool 内存池管理。 49 | 50 | 第二级配置器的原理: 51 | 52 | * 当配置区块超过 128 bytes,就使用第一级配置器 53 | * 当配置区块小于 128 bytes,使用内存池管理 54 | 55 | ```c 56 | enum {_ALIGN = 8}; // 小型区块的上调边界 57 | enum {_MAX_BYTES = 128}; // 小区区块的上限 58 | enum {_NFREELISTS = 16}; // _MAX_BYTES/_ALIGN free-list 的个数 59 | 60 | // free-list 的节点结构,降低维护链表 list 带来的额外负担 61 | union _Obj { 62 | union _Obj* _M_free_list_link; // 利用联合体特点 63 | char _M_client_data[1]; /* The client sees this. */ 64 | }; 65 | static _Obj* __STL_VOLATILE _S_free_list[_NFREELISTS];  // 注意,它是数组,每个数组元素包含若干相等的小额区块 66 | ``` 67 | 68 | 其中 free-list 是指针数组,16 个数组元素,就是 16 个 free-list,各自管理大小分别为 8, 16, 24, 32,...128 bytes(8 的倍数)的小额区块。 69 | 70 | 小额区块的结构体 `union _Obj` 使用链表连接起来。 71 | 72 | 配置器负责配置,同时也负责回收。 73 | 74 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/allocator_memorypool.PNG) 75 | 76 | 77 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/allocator/alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996-1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | */ 13 | 14 | #ifndef __SGI_STL_ALLOC_H 15 | #define __SGI_STL_ALLOC_H 16 | 17 | #ifndef __STL_CONFIG_H 18 | #include 19 | #endif 20 | #ifndef __SGI_STL_INTERNAL_ALLOC_H 21 | #include 22 | #endif 23 | 24 | #ifdef __STL_USE_NAMESPACES 25 | 26 | using __STD::__malloc_alloc_template; 27 | using __STD::malloc_alloc; 28 | using __STD::simple_alloc; 29 | using __STD::debug_alloc; 30 | using __STD::__default_alloc_template; 31 | using __STD::alloc; 32 | using __STD::single_client_alloc; 33 | #ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG 34 | using __STD::__malloc_alloc_oom_handler; 35 | #endif /* __STL_STATIC_TEMPLATE_MEMBER_BUG */ 36 | #ifdef __STL_USE_STD_ALLOCATORS 37 | using __STD::allocator; 38 | #endif /* __STL_USE_STD_ALLOCATORS */ 39 | 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_ALLOC_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/allocator/defalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | */ 15 | 16 | // Inclusion of this file is DEPRECATED. This is the original HP 17 | // default allocator. It is provided only for backward compatibility. 18 | // This file WILL BE REMOVED in a future release. 19 | // 20 | // DO NOT USE THIS FILE unless you have an old container implementation 21 | // that requires an allocator with the HP-style interface. 22 | // 23 | // Standard-conforming allocators have a very different interface. The 24 | // standard default allocator is declared in the header . 25 | 26 | /* 这是原始的 HP default allocator,提供它只是为了回溯兼容。 */ 27 | 28 | #ifndef DEFALLOC_H 29 | #define DEFALLOC_H 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | template 40 | inline T* allocate(ptrdiff_t size, T*) { 41 | set_new_handler(0); // 为了卸载目前的内存分配异常处理函数,强制C++在内存不够的时候抛出std:bad_alloc。 42 | // 申请size个T类型大小的空间 43 | T* tmp = (T*)(::operator new((size_t)(size * sizeof(T)))); 44 | if (tmp == 0) { 45 | cerr << "out of memory" << endl; 46 | exit(1); 47 | } 48 | return tmp; 49 | } 50 | 51 | 52 | template 53 | inline void deallocate(T* buffer) { 54 | ::operator delete(buffer); 55 | } 56 | 57 | template 58 | class allocator { 59 | public: 60 | typedef T value_type; 61 | typedef T* pointer; 62 | typedef const T* const_pointer; 63 | typedef T& reference; 64 | typedef const T& const_reference; 65 | typedef size_t size_type; 66 | typedef ptrdiff_t difference_type; 67 | pointer allocate(size_type n) { 68 | return ::allocate((difference_type)n, (pointer)0); 69 | } 70 | void deallocate(pointer p) { ::deallocate(p); } 71 | pointer address(reference x) { return (pointer)&x; } 72 | const_pointer const_address(const_reference x) { 73 | return (const_pointer)&x; 74 | } 75 | size_type init_page_size() { 76 | return max(size_type(1), size_type(4096/sizeof(T))); 77 | } 78 | size_type max_size() const { 79 | return max(size_type(1), size_type(UINT_MAX/sizeof(T))); 80 | } 81 | }; 82 | 83 | class allocator { 84 | public: 85 | typedef void* pointer; 86 | }; 87 | 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/README.md: -------------------------------------------------------------------------------- 1 | ## 容器(container) 2 | 3 | 容器:包括序列式容器和关联式容器;即各种数据结构,如 vector,list,deque,set,map 等用来存储数据;从实现的角度来看,STL 容器是一种 class template。 4 | 5 | 任何特定的数据结构都是为了实现某种特定的算法。 6 | 7 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/container.PNG) 8 | 9 | ## [序列式容器(sequence container)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/container/sequence%20container) 10 | 11 | * array (C++ 提供,build-in) 12 | * vector 13 | * heap (内含一个 vector) 14 | * priority-queue (内含一个 heap) 15 | * list 16 | * slist (非标准) 17 | * deque 18 | * stack (内含一个 deque) (adapter 配接器) 19 | * queue (内含一个 deque) (adapter 配接器) 20 | 21 | 怎么理解序列式容器,其中的元素都可序(ordered), 但未必有序(sorted)? 22 | 23 | ordered 是容器集合被排序,可以使用指定的顺序去遍历集合。 sorted 是一个容器集合根据某些规则确定排序的。 24 | 25 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/sequencecontainer.PNG) 26 | 27 | ## [关联式容器(associative container)](https://github.com/steveLauwh/SGI-STL/tree/master/The%20Annotated%20STL%20Sources%20V3.3/container/associative%20container) 28 | 29 | * RB-tree (非公开) 30 | * set (内含一个 RB-tree) 31 | * map (内含一个 RB-tree) 32 | * multiset (内含一个 RB-tree) 33 | * multimap (内含一个 RB-tree) 34 | * hashtable (非标准) 35 | * hash_set (内含一个 hashtable) (非标准) 36 | * hash_map (内含一个 hashtable) (非标准) 37 | * hash_multiset (内含一个 hashtable) (非标准) 38 | * hash_multimap (内含一个 hashtable) (非标准) 39 | 40 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/associativecontainer.PNG) 41 | 42 | 熟悉关联式容器,需要有 [RB-tree](https://github.com/steveLauwh/Data-Structures-And-Algorithms/tree/master/Tree/RB-tree)(红黑树原理) 和 [hash table](https://github.com/steveLauwh/Data-Structures-And-Algorithms/tree/master/Hash%20Table)(哈希表原理) 基础。 43 | 44 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/RB-tree/README.md: -------------------------------------------------------------------------------- 1 | ## Red Black Tree 2 | 3 | 红黑树原理:[RB-tree](https://github.com/steveLauwh/Data-Structures-And-Algorithms/tree/master/Tree/RB-tree) 4 | 5 | ### SGI STL RB-tree 实现技巧 6 | 7 | ```cpp 8 | typedef _Rb_tree_node* _Link_type; 9 | 10 | _Rb_tree_node<_Tp>* _M_header; 11 | 12 | // 利用 header 快速找到 RB-tree 最小值,最大值,根节点 13 | _Link_type& _M_root() const 14 | { return (_Link_type&) _M_header->_M_parent; } 15 | _Link_type& _M_leftmost() const 16 | { return (_Link_type&) _M_header->_M_left; } 17 | _Link_type& _M_rightmost() const 18 | { return (_Link_type&) _M_header->_M_right; } 19 | 20 | _S_color(_M_header) = _S_rb_tree_red; // header 的颜色为红色 21 | ``` 22 | 23 | SGI STL 特别为 root 根节点设计一个父节点 header,同时 header 的父节点为 root 根节点。 24 | 25 | ```cpp 26 | // 插入新值,节点键值允许重复 27 | template 29 | typename _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>::iterator 30 | _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc> 31 | ::insert_equal(const _Value& __v) 32 | { 33 | _Link_type __y = _M_header; 34 | _Link_type __x = _M_root(); // 从根节点开始 35 | while (__x != 0) { 36 | __y = __x; 37 | // 当插入值大于当前节点的值,向右,否则反之 38 | __x = _M_key_compare(_KeyOfValue()(__v), _S_key(__x)) ? 39 | _S_left(__x) : _S_right(__x); 40 | } 41 | return _M_insert(__x, __y, __v); // __x 为插入节点,__y 为插入节点的父节点, __v 为插入节点的值 42 | } 43 | ``` 44 | 45 | ```cpp 46 | // 插入新值,节点键值不允许重复,唯一 47 | template 49 | pair::iterator, 50 | bool> 51 | _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc> 52 | ::insert_unique(const _Value& __v) 53 | { 54 | _Link_type __y = _M_header; 55 |  _Link_type __x = _M_root(); // 从根节点开始 56 |  bool __comp = true; 57 |  while (__x != 0) { // 找适当位置插入 58 |    __y = __x; 59 | __comp = _M_key_compare(_KeyOfValue()(__v), _S_key(__x)); 60 | __x = __comp ? _S_left(__x) : _S_right(__x); 61 | } 62 |  iterator __j = iterator(__y);   // 迭代器 __j 指向插入节点之父节点 __y 63 |  if (__comp) 64 |    if (__j == begin())     // 插入节点为父节点的最左节点 65 | return pair(_M_insert(__x, __y, __v), true); 66 | else 67 | --__j; 68 |  if (_M_key_compare(_S_key(__j._M_node), _KeyOfValue()(__v))) // 不重复,执行 69 |    return pair(_M_insert(__x, __y, __v), true); 70 |  return pair(__j, false); // 重复,不插入 71 | } 72 | ``` 73 | ## 总结 74 | 75 | 插入新节点或者删除旧节点,需要维护 header 节点、需要满足 RB-tree 特性。 76 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/RB-tree/tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1996,1997 4 | * Silicon Graphics Computer Systems, Inc. 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Silicon Graphics makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1994 16 | * Hewlett-Packard Company 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Hewlett-Packard Company makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | * 26 | * 27 | */ 28 | 29 | #ifndef __SGI_STL_TREE_H 30 | #define __SGI_STL_TREE_H 31 | 32 | #ifndef __SGI_STL_INTERNAL_TREE_H 33 | #include 34 | #endif 35 | #include 36 | #include 37 | 38 | #ifdef __STL_USE_NAMESPACES 39 | using __STD::rb_tree; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_TREE_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_map/README.md: -------------------------------------------------------------------------------- 1 | ## hash_map 2 | 3 | * hash_map 的元素结构: 键值对 4 | * hash_map 底层机制为 hash table 5 | * hash_map 元素是无序的,不会自动排序 6 | * hash_map 默认使用 hashtable 大小为 100 7 | * hash_map 不允许键值重复的元素 8 | 9 | ```cpp 10 | // hash_map 实现 11 | template 13 | class hash_map 14 | { 15 | private: 16 | typedef hashtable,_Key,_HashFcn, 17 | _Select1st >,_EqualKey,_Alloc> _Ht; // 底层机制 hash table 18 | _Ht _M_ht; 19 | public: 20 | hash_map(const value_type* __f, const value_type* __l) 21 | : _M_ht(100, hasher(), key_equal(), allocator_type()) 22 | { _M_ht.insert_unique(__f, __l); } // hash_map 不允许键值有重复的元素 23 | }; 24 | ``` 25 | 26 | ## hash_multimap 27 | 28 | * hash_multimap 可以允许键值重复的元素,其它与 hash_map 特性相同 29 | 30 | ```cpp 31 | template 33 | class hash_multimap 34 | { 35 | private: 36 | typedef hashtable, _Key, _HashFcn, 37 | _Select1st >, _EqualKey, _Alloc> _Ht; // 底层机制也是 hash table 38 | _Ht _M_ht; 39 | public: 40 | hash_multimap(const value_type* __f, const value_type* __l) 41 | : _M_ht(100, hasher(), key_equal(), allocator_type()) 42 | { _M_ht.insert_equal(__f, __l); } // 与 hash_map 唯一差别是允许键值重复 43 | }; 44 | ``` 45 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_map/hash_map: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_MAP 28 | #define __SGI_STL_HASH_MAP 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | 36 | #endif /* __SGI_STL_HASH_MAP */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_map/hash_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_MAP_H 28 | #define __SGI_STL_HASH_MAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::hash; 39 | using __STD::hashtable; 40 | using __STD::hash_map; 41 | using __STD::hash_multimap; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | 45 | #endif /* __SGI_STL_HASH_MAP_H */ 46 | 47 | // Local Variables: 48 | // mode:C++ 49 | // End: 50 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_set/README.md: -------------------------------------------------------------------------------- 1 | ## hash_set 2 | 3 | * hash_set 底层实现机制是 hash table,所以 hash_set 内部实现就是封装 hashtable 类 4 | * hash_set 的键值就是实值 5 | * hash_set 不允许有重复元素存在,因为底层调用 hashtable 的 insert_unique() 6 | * hash_set 默认指定 hashtable 大小为 100(质数 193) 7 | * hash_set 元素是无序的 8 | 9 | ```cpp 10 | // hash_set 实现 11 | template 12 | class hash_set 13 | { 14 | private: 15 | typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, 16 | _EqualKey, _Alloc> _Ht; // 底层机制 hash table 17 | _Ht _M_ht; 18 | public: 19 | hash_set(const value_type* __f, const value_type* __l) 20 | : _M_ht(100, hasher(), key_equal(), allocator_type()) 21 | { _M_ht.insert_unique(__f, __l); } 22 | .... 23 | }; 24 | ``` 25 | 26 | ## hash_multiset 27 | 28 | * hash_multiset 与 hash_set 除了底层调用 hashtable 的 insert_equal(),允许重复元素存在;其它特性都相同 29 | 30 | ```cpp 31 | // hash_multiset 实现 32 | template 33 | class hash_multiset 34 | { 35 | private: 36 | typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, 37 | _EqualKey, _Alloc> _Ht; // 底层机制 hash table 38 | _Ht _M_ht; 39 | public: 40 | hash_multiset(const value_type* __f, const value_type* __l) 41 | : _M_ht(100, hasher(), key_equal(), allocator_type()) 42 | { _M_ht.insert_equal(__f, __l); } // 与 hash_set 唯一差别,允许键值重复 43 | .... 44 | ``` 45 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_set/hash_set: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_SET 28 | #define __SGI_STL_HASH_SET 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | 36 | #endif /* __SGI_STL_HASH_SET */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hash_set/hash_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | #ifndef __SGI_STL_HASH_SET_H 28 | #define __SGI_STL_HASH_SET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_HASHTABLE_H 31 | #include 32 | #endif 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::hash; 39 | using __STD::hashtable; 40 | using __STD::hash_set; 41 | using __STD::hash_multiset; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | #endif /* __SGI_STL_HASH_SET_H */ 45 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hashtable/README.md: -------------------------------------------------------------------------------- 1 | ## hashtable 2 | 3 | 哈希表原理:[hash table](https://github.com/steveLauwh/Data-Structures-And-Algorithms/tree/master/Hash%20Table) 4 | 5 | SGI STL hash table 使用(separate chaining)开链法来解决(碰撞 collision)问题。 6 | 7 | ### hashtable 内部实现 8 | 9 | * 桶 buckets:用 vector 表示 10 | * hash table 节点:链表的节点 11 | 12 | 大致描述:对于一个数,进行散列函数处理,获得一个索引(就是桶的节点);当数量很大时,经过散列函数处理,会得到相同的索引,那么桶的节点位置一样, 13 | 此时,将相同的节点使用链表连接起来。 14 | 15 | ```cpp 16 | // hash table 节点 17 | template 18 | struct _Hashtable_node 19 | { 20 | _Hashtable_node* _M_next; 21 | _Val _M_val; 22 | }; 23 | ``` 24 | 25 | hash table 迭代器必须永远维持整个 "buckets vector" 的关系,同时并记录目前所指的节点。hash table 迭代器类型为 forward_iterator。 26 | 27 | 迭代器进行 operator++ 操作,如果目前节点正好是当前 list 的尾端,就跳到下一个 bucket 上。 28 | 29 | ```cpp 30 | // hash table 迭代器 31 | template 33 | struct _Hashtable_iterator { 34 | typedef hashtable<_Val,_Key,_HashFcn,_ExtractKey,_EqualKey,_Alloc> _Hashtable; 35 | typedef _Hashtable_node<_Val> _Node; // hash table 节点 36 | 37 | typedef forward_iterator_tag iterator_category; // 迭代器类型:前向迭代器 38 | 39 | _Node* _M_cur; // 迭代器目前所指的节点 40 | _Hashtable* _M_ht; // 保持对容器的连接关系,bucket 41 | ... 42 | }; 43 | ``` 44 | 45 | ```cpp 46 | // hash table 数据结构 47 | // _Val 节点的实值类型,_Key 节点的键值类型,_HashFcn 哈希函数的类型 48 | // _ExtractKey 从节点中取出键值的方法,_EqualKey 判断键值是否相同的方法 49 | // _Alloc 空间配置器 50 | template 52 | class hashtable { 53 | public: 54 | public: 55 | typedef _Key key_type; // 节点的键值 56 | typedef _Val value_type; // 节点的实值 57 | typedef _HashFcn hasher; // 哈希函数 58 | typedef _EqualKey key_equal; // 判断键值是否相同 59 | private: 60 | typedef _Hashtable_node<_Val> _Node; // 节点 61 | vector<_Node*,_Alloc> _M_buckets; // vector 容器 62 | }; 63 | ``` 64 | 65 | ```cpp 66 |  // 接受键值和 buckets 个数,求出该元素在属于 bucket 67 |  size_type _M_bkt_num_key(const key_type& __key, size_t __n) const 68 | { 69 | return _M_hash(__key) % __n; 70 | } 71 | ``` 72 | 73 | SGI STL 使用质数来设计 buckets 个数,质数从 53 开始,总共 28 个质数,当用户需要多少个 buckets,选取“最接近某数并大于某数”的质数。 74 | 75 | ### 总结 76 | 77 | SGI STL 的 hash table 实现由 vector 和 linked list 组合而成。 78 | 79 | SGI STL 默认的 hash function 是计算元素位置的函数,元素类型只支持 `char*`,`char`,`int`,`long`,`short`。 80 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hashtable/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996,1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_HASHTABLE_H 32 | #define __SGI_STL_HASHTABLE_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __STL_USE_NAMESPACES 40 | using __STD::hash; 41 | using __STD::hashtable; 42 | #endif /* __STL_USE_NAMESPACES */ 43 | 44 | #endif /* __SGI_STL_HASHTABLE_H */ 45 | 46 | // Local Variables: 47 | // mode:C++ 48 | // End: 49 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/hashtable/stl_hash_fun.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996-1998 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | * 14 | * Copyright (c) 1994 15 | * Hewlett-Packard Company 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Hewlett-Packard Company makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | * 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | #ifndef __SGI_STL_HASH_FUN_H 32 | #define __SGI_STL_HASH_FUN_H 33 | 34 | #include 35 | 36 | __STL_BEGIN_NAMESPACE 37 | 38 | template struct hash { }; 39 | 40 | // 对字符字符串进行转换 41 | inline size_t __stl_hash_string(const char* __s) 42 | { 43 | unsigned long __h = 0; 44 | for ( ; *__s; ++__s) 45 | __h = 5*__h + *__s; 46 | 47 | return size_t(__h); 48 | } 49 | 50 | __STL_TEMPLATE_NULL struct hash 51 | { 52 | size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 53 | }; 54 | 55 | __STL_TEMPLATE_NULL struct hash 56 | { 57 | size_t operator()(const char* __s) const { return __stl_hash_string(__s); } 58 | }; 59 | 60 | // 其它类型,直接返回原值 61 | __STL_TEMPLATE_NULL struct hash { 62 | size_t operator()(char __x) const { return __x; } 63 | }; 64 | __STL_TEMPLATE_NULL struct hash { 65 | size_t operator()(unsigned char __x) const { return __x; } 66 | }; 67 | __STL_TEMPLATE_NULL struct hash { 68 | size_t operator()(unsigned char __x) const { return __x; } 69 | }; 70 | __STL_TEMPLATE_NULL struct hash { 71 | size_t operator()(short __x) const { return __x; } 72 | }; 73 | __STL_TEMPLATE_NULL struct hash { 74 | size_t operator()(unsigned short __x) const { return __x; } 75 | }; 76 | __STL_TEMPLATE_NULL struct hash { 77 | size_t operator()(int __x) const { return __x; } 78 | }; 79 | __STL_TEMPLATE_NULL struct hash { 80 | size_t operator()(unsigned int __x) const { return __x; } 81 | }; 82 | __STL_TEMPLATE_NULL struct hash { 83 | size_t operator()(long __x) const { return __x; } 84 | }; 85 | __STL_TEMPLATE_NULL struct hash { 86 | size_t operator()(unsigned long __x) const { return __x; } 87 | }; 88 | 89 | __STL_END_NAMESPACE 90 | 91 | #endif /* __SGI_STL_HASH_FUN_H */ 92 | 93 | // Local Variables: 94 | // mode:C++ 95 | // End: 96 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/map/README.md: -------------------------------------------------------------------------------- 1 | ## map 2 | 3 | map 的底层机制是 RB-tree(红黑树),插入,删除,查找的时间复杂度都是 O(logn)。 4 | 5 | ```cpp 6 | template 7 | class map { 8 | public: 9 | typedef _Key key_type; // 键值类型 10 | typedef _Tp data_type; // 实值类型 11 | typedef _Tp mapped_type; 12 | typedef pair value_type; // 元素类型(键值/实值) 13 | typedef _Compare key_compare; // 键值比较函数 14 | 15 | private: 16 | typedef _Rb_tree, key_compare, _Alloc> _Rep_type; // map 的底层机制 RB-tree 18 | _Rep_type _M_t; // red-black tree representing map 以红黑树(RB-tree) 表现 map 19 | 20 | public: 21 | typedef typename _Rep_type::iterator iterator; // map 迭代器 22 | }; 23 | ``` 24 | 25 | ## 总结 26 | 27 | * map 的结构是键值对 ,键值是唯一的 28 | * 键值是有序 29 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/map/map: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MAP 28 | #define __SGI_STL_MAP 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_MAP */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/map/map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MAP_H 28 | #define __SGI_STL_MAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::map; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/map/pair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_PAIR_H 28 | #define __SGI_STL_PAIR_H 29 | 30 | #ifndef __STL_CONFIG_H 31 | #include 32 | #endif 33 | #ifndef __SGI_STL_INTERNAL_RELOPS 34 | #include 35 | #endif 36 | #ifndef __SGI_STL_INTERNAL_PAIR_H 37 | #include 38 | #endif 39 | 40 | #ifdef __STL_USE_NAMESPACES 41 | 42 | using __STD::pair; 43 | using __STD::make_pair; 44 | 45 | #endif /* __STL_USE_NAMESPACES */ 46 | 47 | #endif /* __SGI_STL_PAIR_H */ 48 | 49 | // Local Variables: 50 | // mode:C++ 51 | // End: 52 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/multimap/multimap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MULTIMAP_H 28 | #define __SGI_STL_MULTIMAP_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::multimap; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MULTIMAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/multiset/multiset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_MULTISET_H 28 | #define __SGI_STL_MULTISET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::multiset; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_MULTISET_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/set/README.md: -------------------------------------------------------------------------------- 1 | ## set 2 | 3 | set 的底层机制为 红黑树(RB-tree)。 4 | 5 | set 的 iterator 被定义为底层 RB-tree 的 const_iterator,所以不能通过迭代器改变 set 的元素值。 6 | 7 | ```cpp 8 | template 9 | class set { 10 | private: 11 | typedef _Rb_tree, key_compare, _Alloc> _Rep_type; // set 的底层实现为 RB-tree 13 | _Rep_type _M_t; // red-black tree representing set 14 | 15 | typedef typename _Rep_type::const_iterator iterator; // iterator 的类型为 const_iterator 16 | }; 17 | ``` 18 | ## 总结 19 | 20 | set 集合: 21 | 22 | * 元素有序 23 | * 元素不能重复,唯一 24 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/set/set: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_SET 28 | #define __SGI_STL_SET 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_SET */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/associative container/set/set.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_SET_H 28 | #define __SGI_STL_SET_H 29 | 30 | #ifndef __SGI_STL_INTERNAL_TREE_H 31 | #include 32 | #endif 33 | #include 34 | #include 35 | #include 36 | 37 | #ifdef __STL_USE_NAMESPACES 38 | using __STD::rb_tree; 39 | using __STD::set; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_SET_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/deque/README.md: -------------------------------------------------------------------------------- 1 | ## deque 2 | 3 | deque 是一种双向进出的连续线性空间。它是动态地分段连续空间组合而成,随时可以增加一段新的空间并链接起来。 4 | 5 | 特点: 6 | 7 | * deque(double-ended queue ,双端队列)是有下标顺序容器,它允许在其首尾两段快速插入及删除 8 | * deque 的元素不是相接存储的,典型实现用单独分配的固定大小数组的序列,外加额外的标记,这表示下标访问必须进行二次指针解引用,与之相比 vector 的下标访问只进行一次 9 | 10 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/deque.PNG) 11 | 12 | ### deque 内部实现原理 13 | 14 | 因为 deque 是一段段的定量连续空间构成。为了方便管理这些一段段连续空间,同时对用户来说,deque 整体是连续的,所以需要采用一小块连续空间 map 作为控制单元,其中 map 中的每个节点 node 都是指针,指向 deque 的一段段连续空间 buffer 缓冲区。 15 | 16 | SGI STL 允许指定 buffer 的大小,默认值为 0 表示将使用 512 bytes 缓冲区。 17 | 18 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/deque%20DS.PNG) 19 | 20 | 一个小块连续空间 map 包含节点数,最少 8 个,最多是所需节点数加上 2。 21 | 22 | ### deque 常见的时间复杂度 23 | 24 | * 随机访问——常数 O(1) 25 | * 在结尾或起始插入或移除元素——常数 O(1) 26 | * 插入或移除元素——线性 O(n) 27 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/deque/deque: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_DEQUE 28 | #define __SGI_STL_DEQUE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __SGI_STL_DEQUE */ 38 | 39 | // Local Variables: 40 | // mode:C++ 41 | // End: 42 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/deque/deque.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_DEQUE_H 28 | #define __SGI_STL_DEQUE_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __STL_USE_NAMESPACES 36 | using __STD::deque; 37 | #endif /* __STL_USE_NAMESPACES */ 38 | 39 | #endif /* __SGI_STL_DEQUE_H */ 40 | 41 | // Local Variables: 42 | // mode:C++ 43 | // End: 44 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/heap/README.md: -------------------------------------------------------------------------------- 1 | ## heap 2 | 3 | heap 的数据结构就是二叉堆(完全二叉树)。 4 | 5 | heap 又分 max-heap(最大堆) 和 min-heap(最小堆)。 6 | 7 | max-heap(最大堆):特点是根节点是最大值,每个节点的键值都大于或等于其子节点键值。 8 | 9 | min-heap(最小堆):特点是根节点是最小值,每个节点的键值都小于或等于其子节点键值。 10 | 11 | ## heap 内部实现 12 | 13 | heap 其实就是一个完全二叉树,怎么保存树节点的值,可以用 array 来储存所有节点,由于 array 无法动态改变大小,就用 vector 代替。 14 | 15 | SGI STL 的 heap 默认是 max-heap,底层容器为 vector。 16 | 17 | 完全二叉树使用层次遍历方式,将树的节点依次存储在 vector 容器中,根节点位于 vector 的头部;当 heap 中的某个节点位于 vector 的 i 处, 18 | 其左子节点位于 vector 的 2i 处,右子节点位于 vector 的 2i+1 处;然后调整为 heap。 19 | 20 | ## heap 操作实现 21 | 22 | * push_heap 是把新元素插入到底层 vector 的 end() 处,然后做 shift up 调整,使其满足 heap 的特性。 23 | 24 | * pop_heap 是将根节点取出(位于 vector 的 begin() 处),然后做 shift down 调整,使其满足 heap 的特性。 25 | 特别注意,pop_heap 只是将根节点的值移动到 vector 的尾部,并没有取出来,vector 的 `[first, last-1)` 位置元素满足 heap 特性;取出使用底部容器 vector 的 pop_back() 操作函数。 26 | 27 | * sort_heap 内部实现就是一直调用 pop_heap,知道迭代器 last 指向 迭代器 first 为止。 28 | 29 | * make_heap 是将一个完全二叉树存储在 vector 中,然后调整为一个 heap,内部调用 __adjust_heap 实现。 30 | 31 | ## heap 没有迭代器 32 | 33 | 因为 heap 遵循某种规律,所以不提供遍历功能,没有迭代器操作。 34 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/heap/heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * Copyright (c) 1997 15 | * Silicon Graphics Computer Systems, Inc. 16 | * 17 | * Permission to use, copy, modify, distribute and sell this software 18 | * and its documentation for any purpose is hereby granted without fee, 19 | * provided that the above copyright notice appear in all copies and 20 | * that both that copyright notice and this permission notice appear 21 | * in supporting documentation. Silicon Graphics makes no 22 | * representations about the suitability of this software for any 23 | * purpose. It is provided "as is" without express or implied warranty. 24 | */ 25 | 26 | #ifndef __SGI_STL_HEAP_H 27 | #define __SGI_STL_HEAP_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __STL_USE_NAMESPACES 33 | 34 | using __STD::push_heap; 35 | using __STD::pop_heap; 36 | using __STD::make_heap; 37 | using __STD::sort_heap; 38 | 39 | #endif /* __STL_USE_NAMESPACES */ 40 | 41 | 42 | #endif /* __SGI_STL_HEAP_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/list/README.md: -------------------------------------------------------------------------------- 1 | ## list 2 | 3 | SGI STL 的 list 是一个双向链表,同时还是一个环状的双向链表;对于任何位置的元素插入或元素移除,list 永远是常数时间。 4 | 5 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/list.PNG) 6 | 7 | ### list 的节点(node) 8 | 9 | ```cpp 10 | // 双向链表 11 | struct _List_node_base { 12 | _List_node_base* _M_next; 13 | _List_node_base* _M_prev; 14 | }; 15 | 16 | // list 节点 17 | template 18 | struct _List_node : public _List_node_base { 19 | _Tp _M_data; // 节点存储的值 20 | }; 21 | ``` 22 | 23 | ### list 的迭代器 24 | 25 | list 的节点可以在存储空间中不连续,所以 list 的迭代器必须具备前移、后移的能力,list 提供是 Bidirectional iterator。 26 | 27 | ```cpp 28 | // List 迭代器基类 29 | struct _List_iterator_base { 30 | typedef size_t size_type; 31 | typedef ptrdiff_t difference_type; 32 | typedef bidirectional_iterator_tag iterator_category; // 双向移动迭代器 33 | 34 | _List_node_base* _M_node; // 迭代器内部当然要有一个普通指针,指向 list 的节点 35 | 36 | _List_iterator_base(_List_node_base* __x) : _M_node(__x) {} 37 | _List_iterator_base() {} 38 | 39 | void _M_incr() { _M_node = _M_node->_M_next; } // 前驱 40 | void _M_decr() { _M_node = _M_node->_M_prev; } // 后继 41 | 42 | // 比较两个容器操作 43 | bool operator==(const _List_iterator_base& __x) const { 44 | return _M_node == __x._M_node; 45 | } 46 | bool operator!=(const _List_iterator_base& __x) const { 47 | return _M_node != __x._M_node; 48 | } 49 | }; 50 | ``` 51 | 52 | ### list 的数据结构 53 | 54 | ```cpp 55 | // list 的基类 56 | template 57 | class _List_base 58 | { 59 | public: 60 | typedef _Alloc allocator_type; 61 | allocator_type get_allocator() const { return allocator_type(); } 62 | 63 | _List_base(const allocator_type&) { 64 | _M_node = _M_get_node(); 65 | _M_node->_M_next = _M_node; 66 | _M_node->_M_prev = _M_node; 67 | } 68 | ~_List_base() { 69 | clear(); 70 | _M_put_node(_M_node); 71 | } 72 | 73 | void clear(); 74 | 75 | protected: 76 | // 专属之空间配置器,每次配置一个节点大小 77 | typedef simple_alloc<_List_node<_Tp>, _Alloc> _Alloc_type; 78 | _List_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); } // 配置一个节点并传回 79 | void _M_put_node(_List_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); } // 释放一个节点 80 | 81 | protected: 82 | _List_node<_Tp>* _M_node; // 只要一个指针,便可表示整个环状双向链表,空白节点 83 | }; 84 | ``` 85 | list 数据结构设计的是环状的双向链表,由于遵循 STL 的前闭后开原则,默认有一个 node 指针刻意置于尾端的一个空白节点。 86 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/list/list: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_LIST 28 | #define __SGI_STL_LIST 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* __SGI_STL_LIST */ 37 | 38 | // Local Variables: 39 | // mode:C++ 40 | // End: 41 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/list/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_LIST_H 28 | #define __SGI_STL_LIST_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifdef __STL_USE_NAMESPACES 35 | using __STD::list; 36 | #endif /* __STL_USE_NAMESPACES */ 37 | 38 | #endif /* __SGI_STL_LIST_H */ 39 | 40 | // Local Variables: 41 | // mode:C++ 42 | // End: 43 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/queue/README.md: -------------------------------------------------------------------------------- 1 | ## queue 2 | 3 | queue 的数据结构特点是 FIFO(先进先出),尾端进,首端出;所以 queue 也是不允许遍历。 4 | 5 | queue 与 stack 一样,以某种容器为底层结构,被称为 container adapter。 6 | 7 | 在 SGI STL 里,queue 默认是以 deque 为底层容器,将 deque 的尾端出关闭,首端进关闭,就可以实现 queue 的功能。 8 | 9 | queue 还可以使用 list 作为底层容器。 10 | 11 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/queue.PNG) 12 | 13 | ## priority_queue 14 | 15 | STL priority_queue 的内部实现:默认情况下,以 vector 为底层容器,加上 heap(默认max-heap) 处理规则;具有权值高者先出的特性。 16 | 17 | 被归为 container adapter,就是对 container 进行封装一层。 18 | 19 | priority_queue 本质还是 queue,只允许在尾部加入元素,并从首部取出元素;只不过内部元素具有优先级,优先级高者先出。 20 | 21 | priority_queue 的所有元素进出具有一定规则,所以不提供遍历功能,也不提供迭代器。 22 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/queue/queue: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | // 提供外部调用 27 | #ifndef __SGI_STL_QUEUE 28 | #define __SGI_STL_QUEUE 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #endif /* __SGI_STL_QUEUE */ 42 | 43 | // Local Variables: 44 | // mode:C++ 45 | // End: 46 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/slist/README.md: -------------------------------------------------------------------------------- 1 | ## slist 2 | 3 | STL slist 作为单链表,如果在尾端插入,效率很低,所以只提供首端插入 push_front() 操作。 4 | 5 | slist 容器并没有归入标准规格。 6 | 7 | C++11 提供 `std::forward_list`(正向链表),与 slist 功能类似。 8 | 9 | [forward_list](http://classfoo.com/ccby/article/5wWLx) 没有像 slist 提供 size() 成员函数,因为 forward_list 类模板是专为极度考虑性能的程序而设计的。 10 | 11 | ctor:constructor 12 | 13 | dtor:destructor 14 | 15 | slist 内部实现就是对单向链表的操作。 16 | 17 | ### vector 和 list 区别 18 | 19 | * vector 拥有一段连续的内存空间,能很好的支持随机存取 20 | 21 | * list 的内存空间可以是不连续,它不支持随机访问;由于链表的特点,能高效地进行插入和删除 22 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/slist/slist: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | // 提供外部使用头文件 15 | #ifndef __SGI_STL_SLIST 16 | #define __SGI_STL_SLIST 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif /* __SGI_STL_SLIST */ 25 | 26 | // Local Variables: 27 | // mode:C++ 28 | // End: 29 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/slist/slist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __SGI_STL_SLIST_H 16 | #define __SGI_STL_SLIST_H 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #ifdef __STL_USE_NAMESPACES 23 | using __STD::slist; 24 | #endif /* __STL_USE_NAMESPACES */ 25 | 26 | #endif /* __SGI_STL_SLIST_H */ 27 | 28 | // Local Variables: 29 | // mode:C++ 30 | // End: 31 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/stack/README.md: -------------------------------------------------------------------------------- 1 | ## stack 2 | 3 | stack(栈) 数据结构的特点是先进后出(一端进出),不允许遍历。 4 | 5 | stack 不像 vector、list、deque 那样独立实现,它是可以使用某种容器作为底部结构,来实现 stack 的功能,更确却说 stack 是 adapter(配接器)。 6 | 7 | SGI STL 里的 stack 使用的是以 deque 为底部结构来实现其所有功能。 8 | 9 | 同时 list(双向开口) 数据结构,只要关闭首端,也可以作为 stack 的底部结构。 10 | 11 | stack 没有迭代器。 12 | 13 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/stack.PNG) 14 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/stack/stack: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | // 此头文件给外部调用 27 | #ifndef __SGI_STL_STACK 28 | #define __SGI_STL_STACK 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __SGI_STL_STACK */ 38 | 39 | // Local Variables: 40 | // mode:C++ 41 | // End: 42 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/stack/stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_STACK_H 28 | #define __SGI_STL_STACK_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef __STL_USE_NAMESPACES 37 | using __STD::stack; 38 | using __STD::queue; 39 | using __STD::priority_queue; 40 | #endif /* __STL_USE_NAMESPACES */ 41 | 42 | #endif /* __SGI_STL_STACK_H */ 43 | 44 | // Local Variables: 45 | // mode:C++ 46 | // End: 47 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/vector/README.md: -------------------------------------------------------------------------------- 1 | ## vector 2 | 3 | ### vector 上的常见操作复杂度 4 | 5 | * 随机访问——常数 O(1) 6 | * 在末尾插入或移除元素——均摊常数 O(1) 7 | * 插入或移除元素到 vector 结尾的距离成线性 O(n) 8 | 9 | ### vector 的迭代器类型 Random Access Iterator 10 | 11 | vector 的迭代器涵盖了指针所有的算术能力(`operator*,operator->,operator++,operator--,operator+,operator-,operator+=,operator-=`), 12 | 同时 vector 支持随机存取,所以 vector 提供是 Random Access Iterator。 13 | 14 | ### vector 的数据结构 15 | 16 | ```cpp 17 | template 18 | class vector 19 | { 20 | public: 21 | typedef T value_type; 22 | typedef value_type* iterator; // vector 的迭代器是普通指针 23 | protected: 24 | iterator start; // 表示目前使用空间的头 25 | iterator finish; // 表示目前使用空间的尾 26 | iterator end_of_storage; // 表示目前可用空间的尾 27 | }; 28 | ``` 29 | 30 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/vector.PNG) 31 | 32 | ### 看 vector 底层实现的记录 33 | 34 | size_type:无符号整数类型(通常是 std::size_t) 35 | 36 | #### uninitialized_fill_n 功能 37 | 38 | ```cpp 39 | template< class ForwardIt, class Size, class T > 40 | ForwardIt uninitialized_fill_n( ForwardIt first, Size count, const T& value ); 41 | ``` 42 | 函数功能是:从 first 起始,将 value 的值复制 count 个。 43 | 44 | 函数的参数: 45 | 46 | * first - 要初始化的元素范围起始 47 | * count - 要构造的元素数量 48 | * value - 构造元素所用的值 49 | 50 | #### uninitialized_copy 功能 51 | 52 | ```cpp 53 | template< class InputIt, class ForwardIt > 54 | ForwardIt uninitialized_copy( InputIt first, InputIt last, ForwardIt d_first ); 55 | ``` 56 | 函数的功能:复制来自范围 `[first, last)` 的元素到始于 d_first 的未初始化内存。 57 | 58 | 函数的参数: 59 | 60 | * first, last - 要复制的元素范围 61 | * d_first - 目标范围的起始 62 | 63 | #### uninitialized_fill 功能 64 | 65 | ```cpp 66 | template< class ForwardIt, class T > 67 | void uninitialized_fill( ForwardIt first, ForwardIt last, const T& value ); 68 | ``` 69 | 函数的功能:复制给定的 value 到以 `[first, last)` 定义的未初始化内存区域。 70 | 71 | 函数的参数: 72 | 73 | * first, last - 要初始化的元素的范围 74 | * value - 构造元素所用的值 75 | 76 | #### copy 功能 77 | 78 | ```cpp 79 | template< class InputIt, class OutputIt > 80 | OutputIt copy( InputIt first, InputIt last, OutputIt d_first ); 81 | ``` 82 | 函数的功能:复制 `[first, last)` 所定义的范围中的元素到始于 d_first 的另一范围。 83 | 84 | 函数的参数: 85 | 86 | * first, last - 要复制的元素范围 87 | * d_first - 目标范围的起始 88 | 89 | #### vector insert 形式 90 | 91 | ```cpp 92 | // 在 pos 前插入 value,底层实现 _M_insert_aux 93 | iterator insert( iterator pos, const T& value ); 94 | 95 | // 在 pos 前插入 value 的 count 个副本,底层实现 _M_fill_insert 96 | void insert( iterator pos, size_type count, const T& value ); 97 | 98 | // 在 pos 前插入来自范围 `[first, last)` 的元素,底层实现 _M_range_insert 99 | template< class InputIt > 100 | void insert( iterator pos, InputIt first, InputIt last); 101 | ``` 102 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/vector/bvector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_BVECTOR_H 28 | #define __SGI_STL_BVECTOR_H 29 | 30 | #include 31 | #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION 32 | #include 33 | #else 34 | #include 35 | #include 36 | #endif 37 | 38 | #include 39 | 40 | #ifdef __STL_USE_NAMESPACES 41 | 42 | using __STD::bit_vector; 43 | 44 | #endif /* __STL_USE_NAMESPACES */ 45 | 46 | #endif /* __SGI_STL_BVECTOR_H */ 47 | 48 | // Local Variables: 49 | // mode:C++ 50 | // End: 51 | 52 | 53 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/vector/vector: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_VECTOR 28 | #define __SGI_STL_VECTOR 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #endif /* __SGI_STL_VECTOR */ 39 | 40 | // Local Variables: 41 | // mode:C++ 42 | // End: 43 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/container/sequence container/vector/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | #ifndef __SGI_STL_VECTOR_H 28 | #define __SGI_STL_VECTOR_H 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __STL_USE_NAMESPACES 36 | using __STD::vector; 37 | #endif /* __STL_USE_NAMESPACES */ 38 | 39 | #endif /* __SGI_STL_VECTOR_H */ 40 | 41 | // Local Variables: 42 | // mode:C++ 43 | // End: 44 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/functor-function object/README.md: -------------------------------------------------------------------------------- 1 | ## 仿函数/函数对象(functor/function object) 2 | 3 | 仿函数/函数对象:行为类似函数,可作为算法的某种策略,从实现的角度来看,仿函数是一种重载了 operator() 的 class 或 class template。 4 | 5 | STL 仿函数应该有能力被函数配接器(function adapter)修饰,为了拥有配接能力,每一个仿函数必须定义自己的相应类型。 6 | 7 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/functionobject.png) 8 | 9 | ### 以操作数的个数划分,可分为一元和二元仿函数 10 | 11 | * `unary_function` 12 | 13 | `unary_function` 用来呈现一元函数的参数类型和返回值类型。 14 | 15 | ```cpp 16 | // 一元函数的参数类型和返回值类型 17 | template 18 | struct unary_function { 19 | typedef _Arg argument_type; 20 | typedef _Result result_type; 21 | }; 22 | ``` 23 | 24 | * `binary_function` 25 | 26 | `binary_function` 用来呈现二元函数的第一参数类型、第二参数类型,以及返回值类型。 27 | 28 | ```cpp 29 | // 二元函数的第一个参数类型和第二个参数类型,以及返回值类型 30 | template 31 | struct binary_function { 32 | typedef _Arg1 first_argument_type; 33 | typedef _Arg2 second_argument_type; 34 | typedef _Result result_type; 35 | }; 36 | ``` 37 | 38 | ### 功能划分 39 | 40 | > 算法类(Arithmetic)仿函数 41 | 42 | STL 内建的 "算术类仿函数",支持加法、减法、乘法、除法、模数和求反运算符。 43 | 44 | > 关系运算类(Relational)仿函数 45 | 46 | STL 内建的 "关系运算类仿函数" 支持等于、不等于、大于、大于等于、小于、小于等于六种运算。 47 | 48 | > 逻辑运算类(Logical)仿函数 49 | 50 | STL 内建的 "逻辑运算类仿函数" 支持了逻辑运算种的 And、Or、Not 三种运算。 51 | 52 | > identity、select、project 53 | 54 | 将其参数原封不动地传回。为了间接性——间接性是抽象化的重要工具。 55 | 56 | 57 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/functor-function object/functional: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997 3 | * Silicon Graphics Computer Systems, Inc. 4 | * 5 | * Permission to use, copy, modify, distribute and sell this software 6 | * and its documentation for any purpose is hereby granted without fee, 7 | * provided that the above copyright notice appear in all copies and 8 | * that both that copyright notice and this permission notice appear 9 | * in supporting documentation. Silicon Graphics makes no 10 | * representations about the suitability of this software for any 11 | * purpose. It is provided "as is" without express or implied warranty. 12 | * 13 | */ 14 | 15 | #ifndef __SGI_STL_FUNCTIONAL 16 | #define __SGI_STL_FUNCTIONAL 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #endif /* __SGI_STL_FUNCTIONAL */ 23 | 24 | // Local Variables: 25 | // mode:C++ 26 | // End: 27 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/iterator/README.md: -------------------------------------------------------------------------------- 1 | ## 迭代器(iterator) 2 | 3 | 迭代器:扮演容器与算法之间的桥梁,是所谓的 “泛型指针”,共有五种类型,以及其它衍生变化。从实现的角度来看,迭代器是一种将 `operator*`,`operator->`,`operator++`,`operator--` 等指针相关操作予以重载的 class template。 所有 STL 容器都附带有自己专属的迭代器。 native pointer 也是一种迭代器。 4 | 5 | ## 迭代器(iterator) 是一种 smart pointer 6 | 7 | 迭代器是一种行为类似指针的对象,而指针的各种行为中最常见的用途是 dereference 和 member access。迭代器最重要的就是对 `operator*` 和 `operator->`进行重载工作。 8 | 9 | auto_ptr:用来包装原生指针(native pointer)的对象,在头文件 中定义。 10 | 11 | 为什么每一种 STL 容器都提供有专属迭代器的缘故。 12 | 13 | 主要是暴露太多细节,所以把迭代器的开发工作交给容器去完成,这样所有实现细节可以得到封装,不被使用者看到。 14 | 15 | ## 迭代器相应类型(associated types) 16 | 17 | 迭代器所指对象的类型。 18 | 19 | 利用 function template 的参数推导机制,只能推导出参数的类型,无法推导出函数返回值类型。 20 | 21 | 迭代器相应类型有五种: 22 | + value type 23 | + difference type 24 | + pointer 25 | + reference 26 | + iterator category 27 | 28 | ![](https://github.com/steveLauwh/SGI-STL/raw/master/The%20Annotated%20STL%20Sources%20V3.3/Other/iteratortraits.PNG) 29 | 30 | ## Traits 编程技术 31 | 32 | traits 意为 “特性”,扮演 “特性萃取机” 角色,萃取各个迭代器的特性(相应类型)。 33 | 34 | template partial specialization 模板偏特化:针对 template 参数更进一步的条件限制所设计出来的一个特化版本,本身仍然是 template。 35 | 36 | ```cpp 37 | tempalte 38 | struct iterator_traits 39 | { 40 | typedef typename I::iterator_category iterator_category; 41 | typedef typename I::value_type value_type; 42 | typedef typename I::difference_type difference_type; 43 | typedef typename I::pointer pointer; 44 | typedef typename I::reference reference; 45 | }; 46 | ``` 47 | 48 | * 迭代器相应类型之一:value type 49 | 50 | value type 就是迭代器所指对象的类型。 51 | 52 | ```cpp 53 | template 54 | typename iterator_traits::value_type func(I ite) 55 | { 56 | return *ite; 57 | } 58 | ``` 59 | 60 | * 迭代器相应类型之二:difference type 61 | 62 | difference type 用来表示两个迭代器之间的距离。 63 | 64 | ```cpp 65 | template 66 | typename iterator_traits::difference_type cout(I first, I last, const T& value) 67 | { 68 | typename iterator_traits::difference_type n = 0; 69 | for (; first != last; ++first) 70 | { 71 | ++n; 72 | } 73 | 74 | return n; 75 | } 76 | ``` 77 | 78 | * 迭代器相应类型之三:reference type 79 | 80 | 在 c++ 中,函数如果要传回左值,都是以 by reference 的方式进行,所以如果 p 是一个迭代器,它的 value type 是 T ,那么`*p` 应该是T& (即reference type) 81 | 82 | * 迭代器相应类型之四:pointer type 83 | 84 | * 迭代器相应类型之五:iterator_category 85 | 86 | + 输入迭代器 (InputIterator) 是能从所指向元素读取的迭代器 (Iterator) 。输入迭代器 (InputIterator) 仅保证单趟算法的合法性。 87 | + 输出迭代器 (OutputIterator) 是能写入所指元素的迭代器 (Iterator) 。 88 | + 向前迭代器 (ForwardIterator) 是一种能从所指向元素读取数据的迭代器 (Iterator) 。 89 | + 双向迭代器 (BidirectionalIterator) 是能双向移动(即自增与自减)的向前迭代器 (ForwardIterator) 。 90 | + 随机访问迭代器 (RandomAccessIterator) 是能在常数时间内移动到指向任何元素的双向迭代器 (BidirectionalIterator) 。 91 | 92 | ## 总结 93 | 94 | traits 本质是什么? 95 | 96 | 多一层间接性,换来灵活性。 97 | 98 | iterator_traits 负责萃取迭代器的特性,__type_traits 负责萃取类型的特性。 99 | 100 | 101 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/iterator/iterator: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996,1997 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | // 实现看 , 该文件供外部调用 28 | #ifndef __SGI_STL_ITERATOR 29 | #define __SGI_STL_ITERATOR 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #ifdef __STL_USE_NEW_IOSTREAMS 36 | #include 37 | #else /* __STL_USE_NEW_IOSTREAMS */ 38 | #include 39 | #endif /* __STL_USE_NEW_IOSTREAMS */ 40 | 41 | #include 42 | #include 43 | 44 | #endif /* __SGI_STL_ITERATOR */ 45 | 46 | // Local Variables: 47 | // mode:C++ 48 | // End: 49 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/iterator/iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | // 实现看 28 | #ifndef __SGI_STL_ITERATOR_H 29 | #define __SGI_STL_ITERATOR_H 30 | 31 | #ifndef __SGI_STL_FUNCTION_H 32 | #include 33 | #endif 34 | #include 35 | 36 | #ifdef __STL_USE_NEW_IOSTREAMS 37 | #include 38 | #else /* __STL_USE_NEW_IOSTREAMS */ 39 | #include 40 | #endif /* __STL_USE_NEW_IOSTREAMS */ 41 | 42 | #ifndef __SGI_STL_INTERNAL_ITERATOR_BASE_H 43 | #include 44 | #endif 45 | #ifndef __SGI_STL_INTERNAL_ITERATOR_H 46 | #include 47 | #endif 48 | #ifndef __TYPE_TRAITS_H 49 | #include 50 | #endif 51 | #ifndef __SGI_STL_INTERNAL_CONSTRUCT_H 52 | #include 53 | #endif 54 | #ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 55 | #include 56 | #endif 57 | 58 | #ifdef __STL_USE_NAMESPACES 59 | 60 | // Names from stl_iterator.h 61 | 62 | using __STD::input_iterator_tag; 63 | using __STD::output_iterator_tag; 64 | using __STD::forward_iterator_tag; 65 | using __STD::bidirectional_iterator_tag; 66 | using __STD::random_access_iterator_tag; 67 | 68 | #if 0 69 | using __STD::iterator; 70 | #endif 71 | using __STD::input_iterator; 72 | using __STD::output_iterator; 73 | using __STD::forward_iterator; 74 | using __STD::bidirectional_iterator; 75 | using __STD::random_access_iterator; 76 | 77 | #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION 78 | using __STD::iterator_traits; 79 | #endif 80 | 81 | using __STD::iterator_category; 82 | using __STD::distance_type; 83 | using __STD::value_type; 84 | 85 | using __STD::distance; 86 | using __STD::advance; 87 | 88 | using __STD::insert_iterator; 89 | using __STD::front_insert_iterator; 90 | using __STD::back_insert_iterator; 91 | using __STD::inserter; 92 | using __STD::front_inserter; 93 | using __STD::back_inserter; 94 | 95 | using __STD::reverse_iterator; 96 | using __STD::reverse_bidirectional_iterator; 97 | 98 | using __STD::istream_iterator; 99 | using __STD::ostream_iterator; 100 | 101 | // Names from stl_construct.h 102 | using __STD::construct; 103 | using __STD::destroy; 104 | 105 | // Names from stl_raw_storage_iter.h 106 | using __STD::raw_storage_iterator; 107 | 108 | #endif /* __STL_USE_NAMESPACES */ 109 | 110 | #endif /* __SGI_STL_ITERATOR_H */ 111 | 112 | // Local Variables: 113 | // mode:C++ 114 | // End: 115 | -------------------------------------------------------------------------------- /The Annotated STL Sources V3.3/iterator/stl_raw_storage_iter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 1994 4 | * Hewlett-Packard Company 5 | * 6 | * Permission to use, copy, modify, distribute and sell this software 7 | * and its documentation for any purpose is hereby granted without fee, 8 | * provided that the above copyright notice appear in all copies and 9 | * that both that copyright notice and this permission notice appear 10 | * in supporting documentation. Hewlett-Packard Company makes no 11 | * representations about the suitability of this software for any 12 | * purpose. It is provided "as is" without express or implied warranty. 13 | * 14 | * 15 | * Copyright (c) 1996 16 | * Silicon Graphics Computer Systems, Inc. 17 | * 18 | * Permission to use, copy, modify, distribute and sell this software 19 | * and its documentation for any purpose is hereby granted without fee, 20 | * provided that the above copyright notice appear in all copies and 21 | * that both that copyright notice and this permission notice appear 22 | * in supporting documentation. Silicon Graphics makes no 23 | * representations about the suitability of this software for any 24 | * purpose. It is provided "as is" without express or implied warranty. 25 | */ 26 | 27 | /* NOTE: This is an internal header file, included by other STL headers. 28 | * You should not attempt to use it directly. 29 | */ 30 | 31 | // 内部头文件 32 | #ifndef __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 33 | #define __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H 34 | 35 | __STL_BEGIN_NAMESPACE 36 | 37 | template 38 | class raw_storage_iterator { 39 | protected: 40 | _ForwardIterator _M_iter; 41 | public: 42 | typedef output_iterator_tag iterator_category; 43 | typedef void value_type; 44 | typedef void difference_type; 45 | typedef void pointer; 46 | typedef void reference; 47 | 48 | explicit raw_storage_iterator(_ForwardIterator __x) : _M_iter(__x) {} 49 | raw_storage_iterator& operator*() { return *this; } 50 | raw_storage_iterator& operator=(const _Tp& __element) { 51 | construct(&*_M_iter, __element); 52 | return *this; 53 | } 54 | raw_storage_iterator<_ForwardIterator, _Tp>& operator++() { 55 | ++_M_iter; 56 | return *this; 57 | } 58 | raw_storage_iterator<_ForwardIterator, _Tp> operator++(int) { 59 | raw_storage_iterator<_ForwardIterator, _Tp> __tmp = *this; 60 | ++_M_iter; 61 | return __tmp; 62 | } 63 | }; 64 | 65 | #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION 66 | 67 | template 68 | inline output_iterator_tag 69 | iterator_category(const raw_storage_iterator<_ForwardIterator, _Tp>&) 70 | { 71 | return output_iterator_tag(); 72 | } 73 | 74 | #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */ 75 | 76 | __STL_END_NAMESPACE 77 | 78 | #endif /* __SGI_STL_INTERNAL_RAW_STORAGE_ITERATOR_H */ 79 | 80 | // Local Variables: 81 | // mode:C++ 82 | // End: 83 | --------------------------------------------------------------------------------