From 6837c510c7ed3a68f59fa3d18024dab4064fc8a2 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 26 Dec 2013 15:59:06 -0800 Subject: [PATCH] Add function template tests. --- tests/run/cpp_template_functions.pyx | 33 +++++++++++++++++++++++++++++++ tests/run/cpp_template_functions_helper.h | 18 +++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/run/cpp_template_functions.pyx create mode 100644 tests/run/cpp_template_functions_helper.h diff --git a/tests/run/cpp_template_functions.pyx b/tests/run/cpp_template_functions.pyx new file mode 100644 index 0000000..d09e802 --- /dev/null +++ b/tests/run/cpp_template_functions.pyx @@ -0,0 +1,33 @@ +# 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) diff --git a/tests/run/cpp_template_functions_helper.h b/tests/run/cpp_template_functions_helper.h new file mode 100644 index 0000000..1b1cead --- /dev/null +++ b/tests/run/cpp_template_functions_helper.h @@ -0,0 +1,18 @@ +template +T one_param(T value) { + return value; +} + +template +std::pair two_params(T a, U b) { + return std::pair(a, b); +} + +template +class A { + public: + template + std::pair method(T a, U b) { + return std::pair(a, b); + } +}; -- 2.7.4