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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<html>
<head>
<title>Boost.Python - <boost/python/stl_iterator.hpp></title>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st August 2002), see www.w3.org" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../boost.css">
</head>
<body>
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
header >
<tr>
<td valign="top" width="300">
<h3><a href="../../../../index.htm"><img height="86" width="277"
alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
</td>
<td valign="top">
<h1 align="center"><a href="../index.html">Boost.Python</a></h1>
<h2 align="center">Header <boost/python/stl_iterator.hpp></h2>
</td>
</tr>
</table>
<hr>
<h2>Contents</h2>
<dl class="page-index">
<dt><a href="#introduction">Introduction</a></dt>
<dt><a href="#classes">Classes</a></dt>
<dd>
<dl class="page-index">
<dt><a href="#stl_input_iterator-spec">Class template
<code>stl_input_iterator</code></a></dt>
<dd>
<dl class="page-index">
<dt><a href="#stl_input_iterator-spec-synopsis">Class
<code>stl_input_iterator</code> synopsis</a></dt>
<dt><a href="#stl_input_iterator-spec-constructors">Class template
<code>stl_input_iterator</code> constructors</a></dt>
<dt><a href="#stl_input_iterator-spec-modifiers">Class template
<code>stl_input_iterator</code> modifiers</a></dt>
<dt><a href="#stl_input_iterator-spec-observers">Class template
<code>stl_input_iterator</code> observers</a></dt>
</dl>
</dd>
</dl>
</dd>
<dt><a href="#examples">Examples</a></dt>
</dl>
<hr>
<h2><a name="introduction"></a>Introduction</h2>
<p><code><boost/python/stl_iterator.hpp></code> provides types
for creating <a href="http://www.sgi.com/tech/stl/Iterators.html">C++
Iterators</a> from <a href="http://www.python.org/doc/current/lib/typeiter.html">
Python iterables</a>.</p>
<h2><a name="classes"></a>Classes</h2>
<h3><a name="stl_input_iterator-spec"></a>Class Template
<code>stl_input_iterator</code></h3>
<p>Instances of <code>stl_input_iterator<T></code> hold a Python
iterator and adapt it for use with STL algorithms.
<code>stl_input_iterator<T></code> satisfies the requirements for
an <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
</p>
<table border="1" summary="stl_input_iterator template parameters">
<tr>
<th>Template Parameter</th>
<th>Requirements</th>
<th>Semantics</th>
<th>Default</th>
</tr>
<tr>
<td><code>ValueType</code></td>
<td><code>ValueType</code> must be CopyConstructible.</td>
<td>Dereferencing an instance of <code>stl_input_iterator<ValueType></code>
will return an rvalue of type <code>ValueType</code>.</td>
<td><i>None</i></td>
</tr>
</table>
<h4><a name="stl_input_iterator-spec-synopsis"></a>Class Template stl_input_iterator
synopsis</h4>
<pre>
namespace boost { namespace python
{
template <class ValueType>
struct stl_input_iterator
{
typedef std::ptrdiff_t difference_type;
typedef ValueType value_type;
typedef ValueType* pointer;
typedef ValueType reference;
typedef std::input_iterator_tag iterator_category;
stl_input_iterator();
stl_input_iterator(<a href="object.html#object-spec">object</a> const& ob);
stl_input_iterator& operator++();
stl_input_iterator operator++(int);
ValueType operator*() const;
friend bool operator==(stl_input_iterator const& lhs, stl_input_iterator const& rhs);
friend bool operator!=(stl_input_iterator const& lhs, stl_input_iterator const& rhs);
private:
<a href="object.html#object-spec">object</a> it; // For exposition only
<a href="object.html#object-spec">object</a> ob; // For exposition only
};
}}
</pre>
<h4>
<a name="stl_input_iterator-spec-constructors"></a>Class Template <code>stl_input_iterator</code>
constructors
</h4>
<pre>
stl_input_iterator()
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Creates a past-the-end input iterator, useful for signifying the end of a sequence.
</dt>
<dt><b>Postconditions:</b> <code>this</code> is past-the-end.</dt>
<dt><b>Throws:</b> Nothing.</dt>
</dl>
<pre>
stl_input_iterator(object const& ob)
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Calls <code>ob.attr("__iter__")()</code> and stores the resulting Python iterator
object in <code>this->it</code>. Then, calls <code>this->it.attr("next")()</code> and
stores the result in <code>this->ob</code>. If the sequence is exhausted, sets
<code>this->ob</code> to <code>object()</code>.
</dt>
<dt><b>Postconditions:</b> <code>this</code> is a dereferenceable or past-the-end.</dt>
</dl>
<h4>
<a name="stl_input_iterator-spec-modifiers"></a>Class Template <code>stl_input_iterator</code>
modifiers
</h4>
<pre>
stl_input_iterator& operator++()
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Calls <code>this->it.attr("next")()</code> and stores the result in
<code>this->ob</code>. If the sequence is exhausted, sets <code>this->ob</code>
to <code>object()</code>.
</dt>
<dt><b>Postconditions:</b> <code>this</code> is a dereferenceable or past-the-end.</dt>
<dt><b>Returns:</b> <code>*this</code>.</dt>
</dl>
<pre>
stl_input_iterator operator++(int)
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
<code>stl_input_iterator tmp = *this; ++*this; return tmp;</code>
</dt>
<dt><b>Postconditions:</b> <code>this</code> is a dereferenceable or past-the-end.</dt>
</dl>
<h4><a name="stl_input_iterator-spec-observers"></a>Class Template<code>stl_input_iterator</code>
observers</h4>
<pre>
ValueType operator*() const
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Returns the current element in the sequence.
</dt>
<dt><b>Returns:</b>
<code>extract<ValueType>(this->ob);</code>
</dt>
</dl>
<pre>
friend bool operator==(stl_input_iterator const& lhs, stl_input_iterator const& rhs)
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Returns true if both iterators are dereferenceable or if both iterators are past-the-end,
false otherwise.
</dt>
<dt><b>Returns:</b>
<code>(lhs.ob == object()) == (rhs.ob == object())</code>
</dt>
</dl>
<pre>
friend bool operator!=(stl_input_iterator const& lhs, stl_input_iterator const& rhs)
</pre>
<dl class="function-semantics">
<dt><b>Effects:</b>
Returns false if both iterators are dereferenceable or if both iterators are past-the-end,
true otherwise.
</dt>
<dt><b>Returns:</b>
<code>!(lhs == rhs)</code>
</dt>
</dl>
<h2><a name="examples"></a>Examples</h2>
<pre>
#include <boost/python/object.hpp>
#include <boost/python/stl_iterator.hpp>
#include <list>
using namespace boost::python;
std::list<int> sequence_to_int_list(object const& ob)
{
stl_input_iterator<int> begin(ob), end;
return std::list<int>(begin, end);
}
</pre>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->30
October, 2005
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
</p>
<p><i>© Copyright Eric Niebler 2005.</i></p>
</body>
</html>
|