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
Gwenaël Samain
cython
Commits
6837c510
Commit
6837c510
authored
Dec 26, 2013
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function template tests.
parent
404c8968
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
tests/run/cpp_template_functions.pyx
tests/run/cpp_template_functions.pyx
+33
-0
tests/run/cpp_template_functions_helper.h
tests/run/cpp_template_functions_helper.h
+18
-0
No files found.
tests/run/cpp_template_functions.pyx
0 → 100644
View file @
6837c510
# tag: cpp
from
libcpp.pair
cimport
pair
cdef
extern
from
"cpp_template_functions_helper.h"
:
cdef
T
one_param
[
T
](
T
)
cdef
pair
[
T
,
U
]
two_params
[
T
,
U
](
T
,
U
)
cdef
cppclass
A
[
T
]:
pair
[
T
,
U
]
method
[
U
](
T
,
U
)
def
test_one_param
(
int
x
):
"""
>>> test_one_param(3)
(3, 3.0)
"""
return
one_param
[
int
](
x
),
one_param
[
double
](
x
)
def
test_two_params
(
int
x
,
int
y
):
"""
>>> test_two_params(1, 2)
(1, 2.0)
"""
return
two_params
[
int
,
double
](
x
,
y
)
def
test_method
(
int
x
,
int
y
):
"""
>>> test_method(5, 10)
((5, 10.0), (5.0, 10))
"""
cdef
A
[
int
]
a_int
cdef
A
[
double
]
a_double
return
a_int
.
method
[
float
](
x
,
y
),
a_double
.
method
[
int
](
x
,
y
)
# return a_int.method[double](x, y), a_double.method[int](x, y)
tests/run/cpp_template_functions_helper.h
0 → 100644
View file @
6837c510
template
<
typename
T
>
T
one_param
(
T
value
)
{
return
value
;
}
template
<
typename
T
,
typename
U
>
std
::
pair
<
T
,
U
>
two_params
(
T
a
,
U
b
)
{
return
std
::
pair
<
T
,
U
>
(
a
,
b
);
}
template
<
typename
T
>
class
A
{
public:
template
<
typename
U
>
std
::
pair
<
T
,
U
>
method
(
T
a
,
U
b
)
{
return
std
::
pair
<
T
,
U
>
(
a
,
b
);
}
};
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