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
3623e6c7
Commit
3623e6c7
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2442 from gabrieldemarmiesse/test_wrapping_cplusplus_2
Added tests for "Using C++ in Cython" part 2
parents
558ef9ec
b5d5a264
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
29 deletions
+32
-29
docs/examples/userguide/wrapping_CPlusPlus/templates.pyx
docs/examples/userguide/wrapping_CPlusPlus/templates.pyx
+30
-0
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-29
No files found.
docs/examples/userguide/wrapping_CPlusPlus/templates.pyx
0 → 100644
View file @
3623e6c7
# distutils: language = c++
# import dereference and increment operators
from
cython.operator
cimport
dereference
as
deref
,
preincrement
as
inc
cdef
extern
from
"<vector>"
namespace
"std"
:
cdef
cppclass
vector
[
T
]:
cppclass
iterator
:
T
operator
*
()
iterator
operator
++
()
bint
operator
==
(
iterator
)
bint
operator
!=
(
iterator
)
vector
()
void
push_back
(
T
&
)
T
&
operator
[](
int
)
T
&
at
(
int
)
iterator
begin
()
iterator
end
()
cdef
vector
[
int
]
*
v
=
new
vector
[
int
]()
cdef
int
i
for
i
in
range
(
10
):
v
.
push_back
(
i
)
cdef
vector
[
int
].
iterator
it
=
v
.
begin
()
while
it
!=
v
.
end
():
print
(
deref
(
it
))
inc
(
it
)
del
v
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
3623e6c7
...
...
@@ -299,36 +299,9 @@ which can also be written ``&foo``.
Templates
----------
Cython uses a bracket syntax for templating. A simple example for wrapping C++ vector:
:
Cython uses a bracket syntax for templating. A simple example for wrapping C++ vector:
# import dereference and increment operators
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "<vector>" namespace "std":
cdef cppclass vector[T]:
cppclass iterator:
T operator*()
iterator operator++()
bint operator==(iterator)
bint operator!=(iterator)
vector()
void push_back(T&)
T& operator[](int)
T& at(int)
iterator begin()
iterator end()
cdef vector[int] *v = new vector[int]()
cdef int i
for i in range(10):
v.push_back(i)
cdef vector[int].iterator it = v.begin()
while it != v.end():
print(deref(it))
inc(it)
del v
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/templates.pyx
Multiple template parameters can be defined as a list, such as ``[T, U, V]``
or ``[int, bool, char]``. Optional template parameters can be indicated
...
...
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