Common Items: Vector Set/multiset Map/multimap List set c VSML set c(operator) SM set c(c2) VSML set c(n) V L set c(n, elem) V L set c(beg, end) VSML set c(beg, end, op) SM c.begin() VSML c.end() VSML c.rbegin() VSML c.rend() VSML c.size() VSML c.empty() VSML c.max_size() VSML c.capacity() V c.reserve() V ==, !=, <, >, <=, >= VSML c1 = c2 VSML c.assign(n,elem) V L c.assign(beg,end) V L c1.swap(c2) VSML swap(c1,c2) VSML c.front() V L c.back() V L c.push_back(elem) V L void c.pop_back() V L c.push_front(elem) L void c.pop_front() L c.insert(pos,elem) VSML c.insert(pos,n,elem) V L c.insert(pos,beg,end) V L c.insert(elem) SM c.insert(beg,end) SM c.erase(elem) SM c.erase(pos) VSML c.erase(beg,end) VSML c.resize(num) V L c.resize(num,elem) V L c.clear() VSML Vector: vec.at(idx) vec[idx] Set, Multiset: set set c.begin() c.end() c.rbegin() c.rend() c.count(value) c.find(value) c.lower_bound(value) c.upper_bound(value) c.equal_range(value) List: li.sort() /* use instead of general sort */ li.remove(val) li.remove_if(op) li.unique() // removes consecutive duplicates li.unique(op) // removes as above if op is true li.splice(pos, li2) li.splice(pos, li2, li2pos) li.splice(pos, li2,, li2beg, li2end) li.sort() li.sort(op) li.merge(li2) li.merge(li2,op) li.reverse ----------- Map, Multimap: map map m.begin() m.end() m.rbegin() m.rend() m.count(key) m.find(key) m.lower_bound(key) m.upper_bound(key) m.equal_range(key) m[key] ------------ Strings: =, assign() swap() +=, append(), push_back() insert() erase() clear() resize() replace() ==, !=, <, <=, >, >=, compare() size(), length() max_size() empty() capacity() reserve() [], at() at() checks bounds; [] trusts the user copy() c_str() data() substr() begin(), end() rbegin, rend() get_allocator() ---------------------------------------- Stack: s.empty() s.size() s.push() s.top() void s.pop() and that's about it. Queue: q.empty() q.size() q.push() q.front() q.back() void q.pop() Priority Queue: priority_queue container type could be deque, vector, or anything with random access (so no lists) and front(), push_back(), and pop_back(). Interface as normal queue. Bitset: ---------------------------------------- Algorithms: for_each (beg, end, op) // Nonmodifying Algorithms: count(beg, end, const &value) //counts items equal to val count_if(beg, end, op) min_element(beg, end) min_element(beg, end, compfunc) max_element(beg, end) max_element(beg, end, compfunc) find(beg, end, value) find_if(beg, end, op) search_n(beg, end, count, value [,op]) // finds n consec. matching elements search(beg, end, searchbeg, searchend [,op]) // search for subrange find_end(beg, end, searchbeg, searchend [,op]) //as above but finds LAST one find_first_of(beg, end, searchbeg, searchend[,op]) // finds ANY, not all adjacent_find(beg, end[,op]) // finds two adjacent equal thins equal(beg, end, cmpbeg[,op]) mismatch(beg, end, cmpbeg[,op]) // returns first difference lexicographical_compare(beg1, end1, beg2, end2 [,op]) // Modifying Algorithms: copy(beg, end, destbeg) copy_backward(beg, end, destend) transform(beg, end, destbeg, unaryop) //copies, but calls op on each element transform(beg, end, beg2, destbeg, binaryop) swap_ranges(beg1, end1, beg2) //foo.swap is prefered when possible fill(beg, end, value) fill_n(beg, num, value) generate(beg, end, op) generate_n(beg, num, op) replace(beg, end, oldvalue, newvalue) replace_if(beg, end, op, newvalue) replace_copy(beg, end, destbeg, oldvalue, newvalue) replace_copy_if(beg, end, destbeg, op, newvalue) // Removing Algorithms: remove(beg, end, value) // doesn't actually remove, just moves to end remove_if(beg, end, op) remove_copy(beg, end, destbeg, value) remove_copy_if(beg, end, destbeg, op) unique(beg, end [,op]) unique_copy(beg, end, destbeg [,op]) // Mutating (reordering) Algorithms: reverse(beg, end) reverse_copy(beg, end, destbeg) rotate(beg, newbeg, end) rotate_copy(beg, newbeg, end, destbeg) next_permutation(beg, end) prev_permutation(beg, end) random_shuffle(beg, end [,op]) partition(beg, end, op) stable_partition(beg, end, op) // Sorting Algorithms: sort(beg, end [,op]) // can't use for lists; use list.sort() stable_sort(beg, end [,op]) partial_sort(beg, sortend, end [,op]) partial_sort_copy(beg, end, destbeg, destend [,op]) nth_element(beg, nth, end [,op]) // Heap Algorithms: make_heap(beg, end [,op]) push_heap(beg, end [,op]) // assuming beg to end-1 is heap, adds end pop_heap(beg, end [,op]) // moves head to end; beg to end-1 is heap sort_heap(beg, end [,op]) // not a heap anymore after this // Sorted Range Algorithms (might work even on unsorted... or might not): bool binary_search(beg, end, value [,op]) // checks existence only bool includes(beg, end, searchbeg, searchend [,op]) // existence of all lower_bound(beg, end, value [,op]) // first item <= value upper_bound(beg, end, value [,op]) // first item > value pair<..> equal_range(beg, end, value [,op]) // both of the above merge(beg1, end1, beg2, end2, destbeg [,op]) set_union(beg1, end1, beg2, end2, destbeg [,op]) set_intersection(beg1, end1, beg2, end2, destbeg [,op]) set_difference(...) // set1 - set2 set_symmetric_difference(...) // like an xor inplace_merge(beg1, end1beg2, end2 [,op]) // Numeric algorithms (include ): accumulate(beg, end, initvalue [,sum_op]) inner_product(beg1, end2, beg2, initvalue [,sum_op, product_op]) partial_sum(beg, end, destbeg [,op]) adjacent_difference(beg, end, destbeg [,op]) ---------------------------------------- Iterators: Reverse iterators must be created with an explicit constructor. They can be converted back to normal iterators with base() Member Function Pointers: Not strictly part of the STL, but I keep having to look up the syntax again and again, so here's a quick summary. Declaring: retval (Class::* fp)(func_args); Assigning: fp = &Class::function; using: Class c, *cp; (c.*fp)(args); // Parenthesis NOT optional (cp->*fp)(args); It is NOT possible to store the result of applying the function pointer to the object (Stroustrup p.419) You might think it would turn into a normal function pointer or something, but apparently it doesn't. With base and derived with virtual functions, you may creat a pointer to a member of the base class, apply it to a member of the derived class, and get the derived class' version of the function in question, as expected. TypeID #include // You cannot actually declare variables of type std::type_info - the // constructor is private. You must save things to references. const std::type_info& t = typeid(object-or-expression); t.name(); // returns const char * // Other than printing the name, comparing to others is all you can do. // You can decode the name with c++filt