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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
444c11c4
Commit
444c11c4
authored
6 years ago
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved a small code snippet to the examples directory.
parent
084a25f5
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
+21
-13
docs/examples/userguide/wrapping_CPlusPlus/python_to_cpp.pyx
docs/examples/userguide/wrapping_CPlusPlus/python_to_cpp.pyx
+19
-0
docs/src/userguide/wrapping_CPlusPlus.rst
docs/src/userguide/wrapping_CPlusPlus.rst
+2
-13
No files found.
docs/examples/userguide/wrapping_CPlusPlus/python_to_cpp.pyx
0 → 100644
View file @
444c11c4
# distutils: language = c++
from
libcpp.string
cimport
string
from
libcpp.vector
cimport
vector
py_bytes_object
=
b'The knights who say ni'
py_unicode_object
=
u'Those who hear them seldom live to tell the tale.'
cdef
string
s
=
py_bytes_object
print
(
s
)
# b'The knights who say ni'
cdef
string
cpp_string
=
<
string
>
py_unicode_object
.
encode
(
'utf-8'
)
print
(
cpp_string
)
# b'Those who hear them seldom live to tell the tale.'
cdef
vector
[
int
]
vect
=
range
(
1
,
10
,
2
)
print
(
vect
)
# [1, 3, 5, 7, 9]
cdef
vector
[
string
]
cpp_strings
=
b'It is a good shrubbery'
.
split
()
print
(
cpp_strings
[
1
])
# b'is'
This diff is collapsed.
Click to expand it.
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
444c11c4
...
...
@@ -374,20 +374,9 @@ how to declare C++ classes.
Since Cython 0.17, the STL containers coerce from and to the
corresponding Python builtin types. The conversion is triggered
either by an assignment to a typed variable (including typed function
arguments) or by an explicit cast, e.g.:
:
arguments) or by an explicit cast, e.g.:
from libcpp.string cimport string
from libcpp.vector cimport vector
cdef string s = py_bytes_object
print(s)
cpp_string = <string> py_unicode_object.encode('utf-8')
cdef vector[int] vect = xrange(1, 10, 2)
print(vect) # [1, 3, 5, 7, 9]
cdef vector[string] cpp_strings = b'ab cd ef gh'.split()
print(cpp_strings[1]) # b'cd'
.. literalinclude:: ../../examples/userguide/wrapping_CPlusPlus/python_to_cpp.pyx
The following coercions are available:
...
...
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