Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xavier Thompson
cython
Commits
1f98bcd7
Commit
1f98bcd7
authored
8 years ago
by
Robert Bradshaw
Browse files
Options
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):
self
.
templates
=
templates
self
.
template_type
=
template_type
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
def
use_conversion_utility
(
self
,
from_or_to
):
...
...
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
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_
;
}
};
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