Commit 04260b51 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved a code snippet to the examples directory.

parent 084a25f5
# distutils: language = c++
from libcpp.vector cimport vector
def main():
cdef vector[int] v
cdef int i, value
for i in range(10):
v.push_back(i)
for value in v:
print(value)
return [x*x for x in v if x % 2 == 0]
......@@ -413,12 +413,9 @@ inside of containers, e.g. a C++ vector of maps of strings.
Iteration over stl containers (or indeed any class with ``begin()`` and
``end()`` methods returning an object supporting incrementing, dereferencing,
and comparison) is supported via the ``for .. in`` syntax (including in list
comprehensions). For example, one can write::
comprehensions). For example, one can write:
cdef vector[int] v = ...
for value in v:
f(value)
return [x*x for x in v if x % 2 == 0]
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/iterate.pyx
If the loop target variable is unspecified, an assignment from type
``*container.begin()`` is used for :ref:`type inference <compiler-directives>`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment