Commit b7ca7dc3 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2447 from gabrieldemarmiesse/test_wrapping_cplusplus_6

Added tests for "Using C++ in Cython" part 6
parents ed6a7e2e 0183926e
# distutils: language = c++
from libcpp.vector cimport vector
def main():
cdef vector[int] v = [4, 6, 5, 10, 3]
cdef int value
for value in v:
print(value)
return [x*x for x in v if x % 2 == 0]
...@@ -351,12 +351,9 @@ inside of containers, e.g. a C++ vector of maps of strings. ...@@ -351,12 +351,9 @@ inside of containers, e.g. a C++ vector of maps of strings.
Iteration over stl containers (or indeed any class with ``begin()`` and Iteration over stl containers (or indeed any class with ``begin()`` and
``end()`` methods returning an object supporting incrementing, dereferencing, ``end()`` methods returning an object supporting incrementing, dereferencing,
and comparison) is supported via the ``for .. in`` syntax (including in list 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 = ... .. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/iterate.pyx
for value in v:
f(value)
return [x*x for x in v if x % 2 == 0]
If the loop target variable is unspecified, an assignment from type If the loop target variable is unspecified, an assignment from type
``*container.begin()`` is used for :ref:`type inference <compiler-directives>`. ``*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