Ticket #6544: iterator_property_map.html

File iterator_property_map.html, 5.3 KB (added by anonymous, 11 years ago)

rewrite of iterator_property_map_html

Line 
1<HTML>
2<!--
3 Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2000
4
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 -->
9<Head>
10<Title>Iterator Property Map Adaptor</Title>
11<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
12 ALINK="#ff0000">
13<IMG SRC="../../../boost.png"
14 ALT="C++ Boost" width="277" height="86">
15
16<BR Clear>
17
18
19<H2><A NAME="sec:iterator-property-map"></A>
20</h2>
21<PRE>
22iterator_property_map&lt;<a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a>, OffsetMap, T, R&gt;
23</PRE>
24
25<P>
26This property map is an adaptor that converts any random access
27iterator into a <a
28href="./LvaluePropertyMap.html">Lvalue Property Map</a>.
29The <tt>OffsetMap</tt> type is responsible for converting
30key objects to integers that can be used as offsets with the
31random access iterator.
32</P>
33
34<h3>Example</h3>
35
36<pre>
37template &lt;typename T&gt;
38typename boost::property_traits&lt;T&gt;::value_type get_value_three(T m)
39{
40 return get(m, 3);
41}
42
43int main()
44{
45 typedef boost::identity_property_map id_map;
46 std::vector&lt;int&gt; fibo;
47
48 fibo.push_back(1);
49 fibo.push_back(1);
50 fibo.push_back(2);
51 fibo.push_back(3);
52 fibo.push_back(5);
53 fibo.push_back(8);
54 fibo.push_back(13);
55
56 boost::iterator_property_map&lt; std::vector&lt;int&gt;::iterator, id_map&gt; fibo_map(fibo.begin() + 2);
57
58 std::cout &lt;&lt; &quot;The sixth fibonacci number is &quot; &lt;&lt; get_value_three(fibo_map) &lt;&lt; std::endl;
59
60 int primes[]={2,3,5,7,11,13,17};
61
62 boost::iterator_property_map&lt; int*, id_map, int, int&amp;&gt; prime_map(&amp;primes[1]);</p>
63
64 std::cout &lt;&lt; &quot;The fifth prime number is &quot; &lt;&lt; get_value_three(prime_map) &lt;&lt;std::endl;
65
66 return 0;
67}
68</pre>
69
70<H3>Where Defined</H3>
71
72<P>
73<a href="../../../boost/property_map/property_map.hpp"><TT>boost/property_map/property_map.hpp</TT></a>
74
75<p>
76<H3>Model Of</H3>
77
78<a href="./LvaluePropertyMap.html">Lvalue Property Map</a>
79
80<P>
81
82<H3>Template Parameters</H3>
83
84<P>
85
86<TABLE border>
87<TR>
88<th>Parameter</th><th>Description</th><th>Default</th>
89</tr>
90
91
92<TR>
93<TD><TT>Iterator</TT></TD>
94<TD>Must be a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>.</TD>
95<TD>&nbsp;</td>
96</tr>
97
98<TR>
99<TD><TT>OffsetMap</TT></TD> <TD>Must be a model of <a
100href="./ReadablePropertyMap.html">Readable Property Map</a>
101and the value type must be convertible to the difference type of the
102iterator.</TD> <TD>&nbsp;</TD>
103</TR>
104
105<TR>
106<TD><TT>T</TT></TD>
107<TD>The value type of the iterator.</TD>
108<TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::value_type</TT></TD>
109</TR>
110
111
112<TR>
113<TD><TT>R</TT></TD>
114<TD>The reference type of the iterator.</TD>
115<TD><TT>std::iterator_traits&lt;RandomAccessIterator&gt;::reference</TT></TD>
116</TR>
117
118</TABLE>
119<P>
120
121<H3>Members</H3>
122
123<P>
124In addition to the methods and functions required by <a
125href="./LvaluePropertyMap.html">Lvalue Property Map</a>, this
126class has the following members.
127
128<hr>
129
130<pre>
131property_traits&lt;iterator_property_map&gt;::value_type
132</pre>
133This is the same type as
134<TT>std::iterator_traits&lt;Iterator&gt;::value_type</TT>.
135
136<hr>
137
138<pre>
139iterator_property_map(Iterator i)
140</pre>
141Constructor. The OffsetMap is default constructed.
142
143<hr>
144
145<pre>
146iterator_property_map(Iterator i, OffsetMap m)
147</pre>
148Constructor.
149
150<hr>
151
152<pre>
153reference operator[](const key_type&amp; v) const
154</pre>
155The operator bracket for property access. The <TT>reference</TT> is from
156<TT>std::iterator_traits&lt;Iterator&gt;</TT> and the <tt>key_type</tt> is from <tt>boost::property_traits&lt;OffsetMap&gt;</tt>.
157<hr>
158
159<h3>Non-Member functions</h3>
160
161<hr>
162
163<pre>
164 template &lt;class RAIter, class OffsetMap&gt;
165 iterator_property_map&lt;RAIter, OffsetMap,
166 typename std::iterator_traits&lt;RAIter&gt;::value_type,
167 typename std::iterator_traits&lt;RAIter&gt;::reference
168 &gt;
169 make_iterator_property_map(RAIter iter, OffsetMap omap)
170</pre>
171A function for conveniently creating an iterator map.
172
173
174<hr>
175
176<pre>
177 template &lt;class RAIter, class OffsetMap, class ValueType&gt;
178 iterator_property_map&lt;RAIter, OffsetMap,
179 typename std::iterator_traits&lt;RAIter&gt;::value_type,
180 typename std::iterator_traits&lt;RAIter&gt;::reference
181 &gt;
182 make_iterator_property_map(RAIter iter, OffsetMap omap, ValueType dummy_arg)
183</pre>
184Use this function instead of the 2-argument version if
185your compiler does not support partial specialization
186(like Visual C++).
187
188
189<hr>
190
191
192<br>
193<HR>
194<TABLE>
195<TR valign=top>
196<TD nowrap>Copyright &copy 2000-2012</TD><TD>
197 <p>
198 <a HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>, Univ.of Notre Dame (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
199 <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Univ.of Notre Dame (<A HREF="mailto:llee1@osl.iu.edu">llee1@osl.iu.edu</A>)<br>
200 <A HREF="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</A>, Univ.of Notre Dame (<A HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)<br>
201 Alex Hagen-Zanker
202 </p></TD></TR></TABLE>
203
204</BODY>
205</HTML>