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
b4fa0cd9
Commit
b4fa0cd9
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2446 from gabrieldemarmiesse/test_wrapping_cplusplus_5
Added tests for "Using C++ in Cython" part 5
parents
4d7de983
444c11c4
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 @
b4fa0cd9
# 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'
docs/src/userguide/wrapping_CPlusPlus.rst
View file @
b4fa0cd9
...
...
@@ -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:
...
...
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