📄 stl_map.h
字号:
* @return An iterator that points to the inserted (key,value) pair. * * This function is not concerned about whether the insertion took place * or not and thus does not return a boolean like the single-argument * insert() does. Note that the first parameter is only a hint and can * potentially improve the performance of the insertion process. A bad * hint would cause no gains in efficiency. */ iterator insert(iterator position, const value_type& __x) { return _M_t.insert_unique(position, __x); } /** * @brief A template function that attemps to insert elements from * another range (possibly another map). * @param first Iterator pointing to the start of the range to be inserted. * @param last Iterator pointing to the end of the range. */ template <class _InputIterator> void insert(_InputIterator __first, _InputIterator __last) { _M_t.insert_unique(__first, __last); } /** * @brief Erases an element from a map. * @param position An iterator pointing to the element to be erased. * * This function erases an element, pointed to by the given iterator, from * a map. Note that this function only erases the element, and that if * the element is itself a pointer, the pointed-to memory is not touched * in any way. Managing the pointer is the user's responsibilty. */ void erase(iterator __position) { _M_t.erase(__position); } /** * @brief Erases an element according to the provided key. * @param x Key of element to be erased. * @return Doc me! (Number of elements that match key? Only makes sense * with multimap) * * This function erases an element, located by the given key, from a map. * Note that this function only erases the element, and that if * the element is itself a pointer, the pointed-to memory is not touched * in any way. Managing the pointer is the user's responsibilty. */ size_type erase(const key_type& __x) { return _M_t.erase(__x); } /** * @brief Erases a [first,last) range of elements from a map. * @param first Iterator pointing to the start of the range to be erased. * @param last Iterator pointing to the end of the range to be erased. * * This function erases a sequence of elements from a map. * Note that this function only erases the element, and that if * the element is itself a pointer, the pointed-to memory is not touched * in any way. Managing the pointer is the user's responsibilty. */ void erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); } /** Erases all elements in a map. Note that this function only erases * the elements, and that if the elements themselves are pointers, the * pointed-to memory is not touched in any way. Managing the pointer is * the user's responsibilty. */ void clear() { _M_t.clear(); } // map operations: /** * @brief Tries to locate an element in a map. * @param x Key of (key, value) pair to be located. * @return Iterator pointing to sought-after element, or end() if not * found. * * This function takes a key and tries to locate the element with which * the key matches. If successful the function returns an iterator * pointing to the sought after pair. If unsuccessful it returns the * one past the end ( end() ) iterator. */ iterator find(const key_type& __x) { return _M_t.find(__x); } /** * @brief Tries to locate an element in a map. * @param x Key of (key, value) pair to be located. * @return Read-only (constant) iterator pointing to sought-after * element, or end() if not found. * * This function takes a key and tries to locate the element with which * the key matches. If successful the function returns a constant iterator * pointing to the sought after pair. If unsuccessful it returns the * one past the end ( end() ) iterator. */ const_iterator find(const key_type& __x) const { return _M_t.find(__x); } /** * @brief Finds the number of elements with given key. * @param x Key of (key, value) pairs to be located. * @return Number of elements with specified key. * * This function only makes sense for multimaps. */ size_type count(const key_type& __x) const { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } /** * @brief Finds the beginning of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @return Iterator pointing to first element matching given key, or * end() if not found. * * This function is useful only with std::multimap. It returns the first * element of a subsequence of elements that matches the given key. If * unsuccessful it returns an iterator pointing to the first element that * has a greater value than given key or end() if no such element exists. */ iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); } /** * @brief Finds the beginning of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @return Read-only (constant) iterator pointing to first element * matching given key, or end() if not found. * * This function is useful only with std::multimap. It returns the first * element of a subsequence of elements that matches the given key. If * unsuccessful the iterator will point to the next greatest element or, * if no such greater element exists, to end(). */ const_iterator lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); } /** * @brief Finds the end of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @return Iterator pointing to last element matching given key. * * This function only makes sense with multimaps. */ iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); } /** * @brief Finds the end of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @return Read-only (constant) iterator pointing to last element matching * given key. * * This function only makes sense with multimaps. */ const_iterator upper_bound(const key_type& __x) const { return _M_t.upper_bound(__x); } /** * @brief Finds a subsequence matching given key. * @param x Key of (key, value) pairs to be located. * @return Pair of iterators that possibly points to the subsequence * matching given key. * * This function improves on lower_bound() and upper_bound() by giving a more * elegant and efficient solution. It returns a pair of which the first * element possibly points to the first element matching the given key * and the second element possibly points to the last element matching the * given key. If unsuccessful the first element of the returned pair will * contain an iterator pointing to the next greatest element or, if no such * greater element exists, to end(). * * This function only makes sense for multimaps. */ pair<iterator,iterator> equal_range(const key_type& __x) { return _M_t.equal_range(__x); } /** * @brief Finds a subsequence matching given key. * @param x Key of (key, value) pairs to be located. * @return Pair of read-only (constant) iterators that possibly points to * the subsequence matching given key. * * This function improves on lower_bound() and upper_bound() by giving a more * elegant and efficient solution. It returns a pair of which the first * element possibly points to the first element matching the given key * and the second element possibly points to the last element matching the * given key. If unsuccessful the first element of the returned pair will * contain an iterator pointing to the next greatest element or, if no such * a greater element exists, to end(). * * This function only makes sense for multimaps. */ pair<const_iterator,const_iterator> equal_range(const key_type& __x) const { return _M_t.equal_range(__x); } template <class _K1, class _T1, class _C1, class _A1> friend bool operator== (const map<_K1, _T1, _C1, _A1>&, const map<_K1, _T1, _C1, _A1>&); template <class _K1, class _T1, class _C1, class _A1> friend bool operator< (const map<_K1, _T1, _C1, _A1>&, const map<_K1, _T1, _C1, _A1>&);};template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return __x._M_t == __y._M_t;}template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return __x._M_t < __y._M_t;}template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return !(__x == __y);}template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return __y < __x;}template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return !(__y < __x);}template <class _Key, class _Tp, class _Compare, class _Alloc>inline bool operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x, const map<_Key,_Tp,_Compare,_Alloc>& __y) { return !(__x < __y);}template <class _Key, class _Tp, class _Compare, class _Alloc>inline void swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y) { __x.swap(__y);}} // namespace std#endif /* _CPP_BITS_STL_MAP_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -