Professional C__ - Marc Gregoire [307]
Constructor taking an initializer_list Assignment operator with an initializer_list key_compare key_comp() const; value_compare value_comp() const; Returns the comparison objects for comparing just keys or entire values constant pair insert(value_type&); iterator insert( iterator, value_type&); void insert( InputIterator start, InputIterator end); Three different forms of insert. The iterator position in the second is a hint, which can be ignored. The range in the third need not be from a container of the same type. Containers that allow duplicate keys return just iterator from the first form, because insert() always succeeds. logarithmic except for the second form, which can be amortized constant if the element is inserted immediately before the given hint. void insert( initializer_list pair emplace( value_type&&); iterator emplace_hint( iterator hint, value_type&&); Implements the C++11 emplace operations to construct objects in-place. In-place construction is discussed in Chapter 12. logarithmic, except for the second form, which can be amortized constant if the element is inserted immediately before the given hint. size_type erase(key_type&); void erase(iterator); void erase( iterator start, iterator end); Three different forms of erase. The first form returns the number of values erased (0 or 1, in containers that do not allow duplicate keys). The second and third forms erase the elements at iterator position, or in the range start to end. logarithmic, except for the second form, which should be amortized constant void clear(); Erases all elements linear iterator find(key_type&); const_iterator find(key_type&) const; Finds the element with the specified key logarithmic size_type count(key_type&) const; Returns the number of elements with the specified key (0 or 1 in containers that do not allow duplicate keys) logarithmic iterator lower_bound( key_type&); iterator upper_bound( key_type&); pair equal_range( key_type&); const_iterator lower_bound( key_type&) const; const_iterator upper_bound( key_type&) const; pair equal_range( key_type&) const; Returns iterators referring to the first element of the specified key, one past the last element of the specified key, or both logarithmic Note that the collection methods lower_bound(), upper_bound(), and equal_range() only make sense on sorted containers. Thus the hashmap class does not need to provide them. Here is the complete hashmap class definition. Note that the prototypes for insert(), erase(), and find() need to change slightly from the previous versions shown, because those initial versions don’t have the right return types required for associative containers: template typename Hash = DefaultHash class hashmap { public: typedef Key key_type; typedef T mapped_type; typedef pair typedef Compare key_compare; typedef pair typedef const pair typedef HashIterator typedef HashIterator typedef size_t size_type; typedef ptrdiff_t difference_type; // Required class definition for associative containers class value_compare : public std::binary_function { friend class hashmap public: bool operator() (const value_type& x, const value_type& y) const { return comp(x.first, y.first);