Commit bc3dd1a2 authored by Stefan Behnel's avatar Stefan Behnel

Add C++ "to_string()" function to declarations.

parent 21aeab70
......@@ -173,3 +173,14 @@ cdef extern from "<string>" namespace "std" nogil:
bint operator>= (const string&)
bint operator>= (const char*)
string to_string(int val)
string to_string(long val)
string to_string (long long val)
string to_string (unsigned val)
string to_string (unsigned long val)
string to_string (unsigned long long val)
string to_string (float val)
string to_string (double val)
string to_string (long double val)
......@@ -3,7 +3,7 @@
cimport cython
from libcpp.string cimport string
from libcpp.string cimport string, to_string
b_asdf = b'asdf'
b_asdg = b'asdg'
......@@ -346,6 +346,18 @@ def test_iteration(string s):
return [c for c in s]
def test_to_string(x):
"""
>>> print(test_to_string(5))
si=5 sl=5
>>> print(test_to_string(-5))
si=-5 sl=-5
"""
si = to_string(<int>x).decode('ascii')
sl = to_string(<long>x).decode('ascii')
return f"si={si} sl={sl}"
_WARNINGS = """
21:31: Cannot pass Python object as C++ data structure reference (string &), will pass by copy.
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment