STL 容器
by Yazy, 2005-6-15STL容器的概念、特性、接口。
Concept | Containerstores other objects(its elements),has an associated iterator type that can be used to iterate through the Container's elements | Forward elements are arranged in a definite order, | Reversible allows backwords iteration through the container, | Random Access provides amortized constant time access to arbitrary elements, |
Associated Types | X::value_type X::iterator X::const_iterator X::reference X::const_reference X::pointer X::difference_type X::size_type | [+Container] | [+Container] X::reverse_iterator X::const_reverse_iterator | [+Container] |
Valid Expressions | a.begin() a.end() a.size() a.max_size() a.empty() a.swap(b) | [+Container] a == b a != b a < b a > b a <= b a >= b | [+Forward Container] a.rbegin() a.rend() | [+Reversible Containe] a[n] |
STL Models | vector | vector deque list set map multiset multimap slist(SGI) hash_set(SGI) hash_map(SGI) hash_multiset(SGI) hash_multimap(SGI) | vector deque list | vector deque |
Concept | Sequencevariable-sized Container,elements are arranged in a strict linear order, supports insertion and removal of elements | Front Insertion insertion at the beginning, | Back Insertion appending an element to the end, |
Associated Types | [+Forward Container] | [+Sequence] | [+Sequence] |
Valid Expressions | [+Forward Container] a.front() a.insert(p, t) a.insert(p, n, t) a.erase(p) a.erase(p,q) a.clear() a.resize(n, t) a.resize(n) | [+Sequence] a.front() a.push_front(t) a.pop_front() | [+Sequence] a.back() a.push_back(t) a.pop_back() |
STL Models | vector deque list slist(SGI) | deque list | vector deque list |
Concept | Associative Containervariable-sized Container,efficient retrieval of elements(values) based on keys, insertion and removal of elements (but not at a specific position) | Simple is an Associative Container where elements are their own keys | Pair associates a key with some other object, | Sorted uses an ordering relation on their keys, |
Associated Types | [+Forward Container] X::key_type | [+Associative Container] (X::key_type is X::value_type) | [+Associative Container] X::data_type | [+Reversible Container] [+Associative Container] X::key_compare X::value_compare |
Valid Expressions | [+Forward Container] a.erase(k):size_type a.erase(p):void a.erase(p, q):void a.clear():void a.find(k):iterator|const_iterator a.count(k):size_type a.equal_range(k):size_type | [+Associative Container] | [+Associative Container] | [+Reversible Container] [+Associative Container] a.key_comp():X::key_compare a.value_compare():X::value_compare a.lower_bound(k):iterator|const_iterator a.upper_bound(k):iterator|const_iterator a.equal_range(k):iterator|const_iterator |
STL Models | set map multiset multimap hash_set(SGI) hash_map(SGI) hash_multiset(SGI) hash_multimap(SGI) | set multiset hash_set(SGI) hash_multiset(SGI) | map multimap hash_map(SGI) hash_multimap(SGI) | set map multiset multimap |
Concept | Unique each key in the container is unique | Multiple there may be more than one element with the same key | Unique Sorted with the property that no two elements in it have the same key | Multiple Sorted any number of elements in it may have equivalent keys. |
Associated Types | [+Associative Container] | [+Associative Container] | [+Sorted Associative Container] [+Unique Associative Container] | [+Sorted Associative Container] [+Multiple Associative Container] |
Valid Expressions | [+Associative Container] a.insert(t):pair<X::iterator, bool> a.insert(t, j):void a.count(k):size_type | [+Associative Container] a.insert(t):X::iterator a.insert(i, j):void | [+Sorted Associative Container] [+Unique Associative Container] a.insert(p, t):iterator a.insert(i, j):void | [+Sorted Associative Container] [+Multiple Associative Container] a.insert(p, t):iterator a.insert(i, j):void |
STL Models | set map hash_set(SGI) hash_map(SGI) | multiset multimap hash_multiset(SGI) hash_multimap(SGI) | set map | multiset multimap |
Concept | Hashed | Unique Hashed | Multiple Hashed | HashFunction(it's not Container.) |
Associated Types | [+Associative Container] X::hasher X::key_equal | [+Hashed Associative Container] [+Unique Associative Container] | [+Hashed Associative Container] [+Multiple Associative Container] | [+Unary Function] (the Result Type must be size_t) |
Valid Expressions | | | | |
STL Models | hash_set hash_map hash_multiset hash_multimap | hash_set(SGI) hash_map(SGI) | hash_multiset(SGI) hash_multimap(SGI) | |