📄 map.html
字号:
<HTML><!-- -- Copyright (c) 1996-1999 -- Silicon Graphics Computer Systems, Inc. -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Silicon Graphics makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- -- Copyright (c) 1994 -- Hewlett-Packard Company -- -- Permission to use, copy, modify, distribute and sell this software -- and its documentation for any purpose is hereby granted without fee, -- provided that the above copyright notice appears in all copies and -- that both that copyright notice and this permission notice appear -- in supporting documentation. Hewlett-Packard Company makes no -- representations about the suitability of this software for any -- purpose. It is provided "as is" without express or implied warranty. -- --><Head><Title>map<Key, Data, Compare, Alloc></Title><!-- Generated by htmldoc --></HEAD><BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" ALINK="#ff0000"> <IMG SRC="CorpID.gif" ALT="SGI" HEIGHT="43" WIDTH="151"> <!--end header--><BR Clear><H1>map<Key, Data, Compare, Alloc></H1><Table CellPadding=0 CellSpacing=0 width=100%><TR><TD Align=left><Img src = "containers.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD><TD Align=right><Img src = "type.gif" Alt="" WIDTH = "194" HEIGHT = "39" ></TD></TR><TR><TD Align=left VAlign=top><b>Category</b>: containers</TD><TD Align=right VAlign=top><b>Component type</b>: type</TD></TR></Table><h3>Description</h3><tt>Map</tt> is a <A href="SortedAssociativeContainer.html">Sorted Associative Container</A> that associates objects oftype <tt>Key</tt> with objects of type <tt>Data</tt>. <tt>Map</tt> is a <A href="PairAssociativeContainer.html">Pair Associative Container</A>, meaning that its value type is<tt><A href="pair.html">pair</A><const Key, Data></tt>. It is also a <A href="UniqueAssociativeContainer.html">Unique Associative Container</A>, meaning that no two elements havethe same key.<P><tt>Map</tt> has the important property that inserting a new elementinto a <tt>map</tt> does not invalidate iterators that point to existingelements. Erasing an element from a <tt>map</tt> also does not invalidateany iterators, except, of course, for iterators that actually point to the element that is being erased.<h3>Example</h3><pre>struct ltstr{ bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; }};int main(){ map<const char*, int, ltstr> months; months["january"] = 31; months["february"] = 28; months["march"] = 31; months["april"] = 30; months["may"] = 31; months["june"] = 30; months["july"] = 31; months["august"] = 31; months["september"] = 30; months["october"] = 31; months["november"] = 30; months["december"] = 31; cout << "june -> " << months["june"] << endl; map<const char*, int, ltstr>::iterator cur = months.find("june"); map<const char*, int, ltstr>::iterator prev = cur; map<const char*, int, ltstr>::iterator next = cur; ++next; --prev; cout << "Previous (in alphabetical order) is " << (*prev).first << endl; cout << "Next (in alphabetical order) is " << (*next).first << endl;}</pre><h3>Definition</h3>Defined in the standard header <A href="map">map</A>, and in the nonstandardbackward-compatibility header <A href="map.h">map.h</A>.<h3>Template parameters</h3><Table border><TR><TH>Parameter</TH><TH>Description</TH><TH>Default</TH></TR><TR><TD VAlign=top><tt>Key</tt></TD><TD VAlign=top>The map's key type. This is also defined as <tt>map::key_type</tt>.</TD><TD VAlign=top> </TD></TR><TR><TD VAlign=top><tt>Data</tt></TD><TD VAlign=top>The map's data type. This is also defined as <tt>map::data_type</tt>.</TD><TD VAlign=top> </TD></TR><TR><TD VAlign=top><tt>Compare</tt></TD><TD VAlign=top>The key comparison function, a <A href="StrictWeakOrdering.html">Strict Weak Ordering</A> whose argument type is <tt>key_type</tt>; it returns <tt>true</tt> if its first argument is less than its second argument, and <tt>false</tt> otherwise. This is also defined as <tt>map::key_compare</tt>.</TD><TD VAlign=top><tt><A href="less.html">less</A><Key></tt></TD></TR><TR><TD VAlign=top><tt>Alloc</tt></TD><TD VAlign=top>The <tt>map</tt>'s allocator, used for all internal memory management.</TD><TD VAlign=top><tt><A href="Allocators.html">alloc</A></tt></TD></tr></table><h3>Model of</h3><A href="UniqueSortedAssociativeContainer.html">Unique Sorted Associative Container</A>, <A href="PairAssociativeContainer.html">Pair Associative Container</A><h3>Type requirements</h3><UL><LI><tt>Data</tt> is <A href="Assignable.html">Assignable</A>.<LI><tt>Compare</tt> is a <A href="StrictWeakOrdering.html">Strict Weak Ordering</A> whose argument type is <tt>Key</tt>.<LI><tt>Alloc</tt> is an <A href="Allocators.html">Allocator</A>.</UL><h3>Public base classes</h3>None.<h3>Members</h3><Table border><TR><TH>Member</TH><TH>Where defined</TH><TH>Description</TH></TR><TR><TD VAlign=top><tt>key_type</tt></TD><TD VAlign=top> <A href="AssociativeContainer.html">Associative Container</A></TD><TD VAlign=top>The <tt>map</tt>'s key type, <tt>Key</tt>.</TD></TR><TR><TD VAlign=top><tt>data_type</tt></TD><TD VAlign=top> <A href="PairAssociativeContainer.html">Pair Associative Container</A></TD><TD VAlign=top>The type of object associated with the keys.</TD></TR><TR><TD VAlign=top><tt>value_type</tt></TD><TD VAlign=top> <A href="PairAssociativeContainer.html">Pair Associative Container</A></TD><TD VAlign=top>The type of object, <tt>pair<const key_type, data_type></tt>, stored in the map.</TD></TR><TR><TD VAlign=top><tt>key_compare</tt></TD><TD VAlign=top> <A href="SortedAssociativeContainer.html">Sorted Associative Container</A></TD><TD VAlign=top> <A href="functors.html">Function object</A> that compares two keys for ordering.</TD></TR><TR><TD VAlign=top><tt>value_compare</tt></TD><TD VAlign=top> <A href="SortedAssociativeContainer.html">Sorted Associative Container</A></TD><TD VAlign=top> <A href="functors.html">Function object</A> that compares two values for ordering.</TD></TR><TR><TD VAlign=top><tt>pointer</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Pointer to <tt>T</tt>.</TD></TR><TR><TD VAlign=top><tt>reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>const_reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>size_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>An unsigned integral type.</TD></TR><TR><TD VAlign=top><tt>difference_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>A signed integral type.</TD></TR><TR><TD VAlign=top><tt>iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Iterator used to iterate through a <tt>map</tt>. <A href="#1">[1]</A></TD></TR><TR><TD VAlign=top><tt>const_iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const iterator used to iterate through a <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Iterator used to iterate backwards through a <tt>map</tt>. <A href="#1">[1]</A></TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Const iterator used to iterate backwards through a <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>iterator begin()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the beginning of the <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>iterator end()</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the end of the <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator begin() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns a <tt>const_iterator</tt> pointing to the beginning of the <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator end() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns a <tt>const_iterator</tt> pointing to the end of the <tt>map</tt>.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator rbegin()</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>reverse_iterator</tt> pointing to the beginning of the reversed map.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator rend()</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>reverse_iterator</tt> pointing to the end of the reversed map.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator rbegin() const</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>const_reverse_iterator</tt> pointing to the beginning of the reversed map.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator rend() const</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>const_reverse_iterator</tt> pointing to the end of the reversed map.</TD></TR><TR><TD VAlign=top><tt>size_type size() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns the size of the <tt>map</tt>.</TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -