Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
e98f32aa
Commit
e98f32aa
authored
Aug 23, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Note on C++ auto and stl iteration.
parent
b62ded56
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+20
-4
No files found.
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
e98f32aa
...
@@ -209,12 +209,12 @@ Declare a var with the wrapped C++ class
...
@@ -209,12 +209,12 @@ Declare a var with the wrapped C++ class
Now, we use cdef to declare a var of the class with the C++ ``new`` statement::
Now, we use cdef to declare a var of the class with the C++ ``new`` statement::
cdef Rectangle *rec
= new Rectangle(1, 2, 3, 4)
rec_ptr
= new Rectangle(1, 2, 3, 4)
try:
try:
recArea = rec.getArea()
recArea = rec
_ptr
.getArea()
...
...
finally:
finally:
del rec # delete heap allocated object
del rec
_ptr
# delete heap allocated object
It's also possible to declare a stack allocated object, as long as it has
It's also possible to declare a stack allocated object, as long as it has
a "default" constructor::
a "default" constructor::
...
@@ -508,7 +508,7 @@ comprehensions). For example, one can write::
...
@@ -508,7 +508,7 @@ comprehensions). For example, one can write::
cdef vector[int] v = ...
cdef vector[int] v = ...
for value in v:
for value in v:
f(value)
f(value)
return [x in v if x % 2 == 0]
return [x
*x for x
in v if x % 2 == 0]
Simplified wrapping with default constructor
Simplified wrapping with default constructor
...
@@ -625,6 +625,22 @@ functions as references (const or otherwise) as it has no impact on the
...
@@ -625,6 +625,22 @@ functions as references (const or otherwise) as it has no impact on the
caller's syntax.
caller's syntax.
``auto`` Keyword
----------------
Though Cython does not have an ``auto`` keyword, Cython local variables
not explicitly typed with ``cdef`` are deduced from the types of the right hand
side of *all* their assignments (see the ``infer_types``
:ref:`compiler directive <compiler-directives>`). This is particularly handy
when dealing with functions that return complicated, nested, templated types,
e.g.::
cdef vector[int] v = ...
it = v.begin()
(Though of course the ``for .. in`` syntax is prefered for objects supporting
the iteration protocol.)
Caveats and Limitations
Caveats and Limitations
========================
========================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment