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
Kirill Smelkov
cython
Commits
4d7de983
Commit
4d7de983
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2448 from gabrieldemarmiesse/test_wrapping_cplusplus_7
Added tests for "Using C++ in Cython" part 7
parents
09e9b502
70c5dca1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
docs/examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
.../examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
+17
-0
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-13
No files found.
docs/examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
0 → 100644
View file @
4d7de983
# distutils: language = c++
from
libcpp.vector
cimport
vector
cdef
class
VectorStack
:
cdef
vector
[
int
]
v
def
push
(
self
,
x
):
self
.
v
.
push_back
(
x
)
def
pop
(
self
):
if
self
.
v
.
empty
():
raise
IndexError
()
x
=
self
.
v
.
back
()
self
.
v
.
pop_back
()
return
x
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
4d7de983
...
...
@@ -438,20 +438,9 @@ Simplified wrapping with default constructor
If your extension type instantiates a wrapped C++ class using the default
constructor (not passing any arguments), you may be able to simplify the
lifecycle handling by tying it directly to the lifetime of the Python wrapper
object. Instead of a pointer attribute, you can declare an instance:
:
object. Instead of a pointer attribute, you can declare an instance:
cdef class VectorStack:
cdef vector[int] v
def push(self, x):
self.v.push_back(x)
def pop(self):
if self.v.empty():
raise IndexError()
x = self.v.back()
self.v.pop_back()
return x
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/wrapper_vector.pyx
Cython will automatically generate code that instantiates the C++ object
instance when the Python object is created and deletes it when the Python
...
...
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