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
Boxiang Sun
cython
Commits
b5d5a264
Commit
b5d5a264
authored
6 years ago
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the template example to the examples directory.
parent
084a25f5
Changes
2
Show 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 @
b5d5a264
# 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
This diff is collapsed.
Click to expand it.
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
b5d5a264
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
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