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
1f98bcd7
Commit
1f98bcd7
authored
Sep 09, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support curiously recurring template pattern.
Closes #1458.
parent
7d763702
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+1
-1
tests/run/curiously_recurring_template_pattern_GH1458.pyx
tests/run/curiously_recurring_template_pattern_GH1458.pyx
+27
-0
tests/run/curiously_recurring_template_pattern_GH1458_suport.h
.../run/curiously_recurring_template_pattern_GH1458_suport.h
+34
-0
No files found.
Cython/Compiler/PyrexTypes.py
View file @
1f98bcd7
...
@@ -3275,7 +3275,7 @@ class CppClassType(CType):
...
@@ -3275,7 +3275,7 @@ class CppClassType(CType):
self
.
templates
=
templates
self
.
templates
=
templates
self
.
template_type
=
template_type
self
.
template_type
=
template_type
self
.
num_optional_templates
=
sum
(
is_optional_template_param
(
T
)
for
T
in
templates
or
())
self
.
num_optional_templates
=
sum
(
is_optional_template_param
(
T
)
for
T
in
templates
or
())
self
.
specializations
=
{}
self
.
specializations
=
{
tuple
(
zip
(
templates
,
templates
)):
self
}
self
.
is_cpp_string
=
cname
in
cpp_string_conversions
self
.
is_cpp_string
=
cname
in
cpp_string_conversions
def
use_conversion_utility
(
self
,
from_or_to
):
def
use_conversion_utility
(
self
,
from_or_to
):
...
...
tests/run/curiously_recurring_template_pattern_GH1458.pyx
0 → 100644
View file @
1f98bcd7
# tag: cpp
cdef
extern
from
"curiously_recurring_template_pattern_GH1458_suport.h"
:
cdef
cppclass
Base
[
T
,
Derived
]:
Base
(
T
)
Derived
half
()
T
calculate
()
cdef
cppclass
Square
[
T
](
Base
[
T
,
Square
[
T
]]):
Square
(
T
)
cdef
cppclass
Cube
[
T
](
Base
[
T
,
Cube
[
T
]]):
Cube
(
T
)
def
test_derived
(
int
x
):
"""
>>> test_derived(5)
(6.25, 8)
"""
try
:
square_double
=
new
Square
[
double
](
x
)
cube_int
=
new
Cube
[
int
](
x
)
return
square_double
.
half
().
calculate
(),
cube_int
.
half
().
calculate
()
finally
:
del
square_double
,
cube_int
tests/run/curiously_recurring_template_pattern_GH1458_suport.h
0 → 100644
View file @
1f98bcd7
template
<
typename
T
,
class
Derived
>
class
Base
{
public:
Base
(
T
x
)
:
x_
(
x
)
{
};
Derived
half
()
{
Derived
d
(
x_
/
2
);
return
d
;
};
virtual
T
calculate
()
=
0
;
virtual
~
Base
()
{
};
protected:
T
x_
;
};
template
<
typename
T
>
class
Square
:
public
Base
<
T
,
Square
<
T
>
>
{
public:
Square
(
T
x
)
:
Base
<
T
,
Square
<
T
>
>
(
x
)
{
};
T
calculate
()
{
return
this
->
x_
*
this
->
x_
;
}
};
template
<
typename
T
>
class
Cube
:
public
Base
<
T
,
Cube
<
T
>
>
{
public:
Cube
(
T
x
)
:
Base
<
T
,
Cube
<
T
>
>
(
x
)
{
};
T
calculate
()
{
return
this
->
x_
*
this
->
x_
*
this
->
x_
;
}
};
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