File: const_assoc_property_map.html

package info (click to toggle)
boost 1.32.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 93,952 kB
  • ctags: 128,458
  • sloc: cpp: 492,477; xml: 52,125; python: 13,519; ansic: 13,013; sh: 1,773; yacc: 853; makefile: 526; perl: 418; lex: 110; csh: 6
file content (194 lines) | stat: -rw-r--r-- 5,444 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<HTML>
<!--
  -- Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
  --
  -- 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.  We make no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  -->
<Head>
<Title>Iterator Property Map Adaptor</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
	ALINK="#ff0000"> 
<IMG SRC="../../boost.png" 
     ALT="C++ Boost" width="277" height="86"> 

<BR Clear>


<H2><A NAME="sec:const-associative-property-map"></A>
</h2>
<PRE>
const_associative_property_map&lt;UniquePairAssociativeContainer&gt;
</PRE>

<P>
This property map is an adaptor that converts any type that is a model
of both <a
href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
Associative Container</a> and <a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a> such as <a
href="http://www.sgi.com/tech/stl/map.html"><tt>std::map</tt></a> into
a constant <a href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
Note that the adaptor only retains a reference to the container, so
the lifetime of the container must encompass the use of the adaptor.
</P>

<h3>Example</h3>

<a href="./example1.cpp">example1.cpp</a>:
<pre>
<font color="#008040">#include &lt;iostream&gt;</font>
<font color="#008040">#include &lt;map&gt;</font>
<font color="#008040">#include &lt;string&gt;</font>
<font color="#008040">#include &lt;boost/property_map.hpp&gt;</font>


<B>template</B> &lt;<B>typename</B> ConstAddressMap&gt;
<B>void</B> display(ConstAddressMap address)
{
  <B>typedef</B> <B>typename</B> boost::property_traits&lt;ConstAddressMap&gt;::value_type
    value_type;
  <B>typedef</B> <B>typename</B> boost::property_traits&lt;ConstAddressMap&gt;::key_type key_type;

  key_type fred = <font color="#0000FF">"Fred"</font>;
  key_type joe = <font color="#0000FF">"Joe"</font>;

  value_type freds_address = get(address, fred);
  value_type joes_address = get(address, joe);
  
  std::cout &lt;&lt; fred &lt;&lt; <font color="#0000FF">": "</font> &lt;&lt; freds_address &lt;&lt; <font color="#0000FF">"\n"</font>
	    &lt;&lt; joe  &lt;&lt; <font color="#0000FF">": "</font> &lt;&lt; joes_address  &lt;&lt; <font color="#0000FF">"\n"</font>;
}

<B>int</B>
main()
{
  std::map&lt;std::string, std::string&gt; name2address;
  boost::const_associative_property_map&lt; std::map&lt;std::string, std::string&gt; &gt;
    address_map(name2address);

  name2address.insert(make_pair(std::string(<font color="#0000FF">"Fred"</font>), 
				std::string(<font color="#0000FF">"710 West 13th Street"</font>)));
  name2address.insert(make_pair(std::string(<font color="#0000FF">"Joe"</font>), 
				std::string(<font color="#0000FF">"710 West 13th Street"</font>)));

  display(address_map);
  
  <B>return</B> EXIT_SUCCESS;
}


</PRE>

<H3>Where Defined</H3>

<P>
<a href="../../boost/property_map.hpp"><TT>boost/property_map.hpp</TT></a>

<p>
<H3>Model Of</H3>

<a href="./LvaluePropertyMap.html">Lvalue Property Map</a>

<P>

<H3>Template Parameters</H3>

<P>

<TABLE border>
<TR>
<th>Parameter</th><th>Description</th><th>Default</th>
</tr>


<TR>
<TD><TT>UniquePairAssociativeContainer</TT></TD> 
<TD>Must be a model of both <a
href="http://www.sgi.com/tech/stl/PairAssociativeContainer.html">Pair
Associative Container</a> and <a
href="http://www.sgi.com/tech/stl/UniqueAssociativeContainer.html">Unique
Associative Container</a> .</TD>
<TD>&nbsp;</td>
</tr>

</TABLE>
<P>

<H3>Members</H3>

<P>
In addition to the methods and functions required by <a
href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
class has the following members.

<hr>

<pre>
property_traits&lt;const_associative_property_map&gt;::value_type
</pre>
This is the same type as
<TT>UniquePairAssociativeContainer::data_type</TT>.

<hr>

<pre>
const_associative_property_map()
</pre>
Default Constructor.

<pre>
const_associative_property_map(const UniquePairAssociativeContainer&amp; c)
</pre>
Constructor.

<hr>

<pre>
const data_type&amp; operator[](const key_type&amp; k) const
</pre>
The operator bracket for property access.
The <TT>key_type</TT> and
<TT>data_type</TT> types are from the typedefs inside of
<TT>UniquePairAssociativeContainer</TT>.

<hr>

<h3>Non-Member functions</h3>

<hr>

<pre>
  template &lt;typename UniquePairAssociativeContainer&gt;
  const_associative_property_map&lt;UniquePairAssociativeContainer&gt;
  make_assoc_property_map(const UniquePairAssociativeContainer&amp; c);
</pre>
A function for conveniently creating an associative property map.



<hr>


<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright &copy 2002</TD><TD>
<a HREF="../../people/jeremy_siek.htm">Jeremy Siek</a>,
Indiana University (<A
HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
<A HREF=http://www.osl.iu.edu/~llee1>Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Indiana University (<A
HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
</TD></TR></TABLE>

</BODY>
</HTML>