More complicated template tests.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 19 Feb 2010 20:00:56 +0000 (12:00 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 19 Feb 2010 20:00:56 +0000 (12:00 -0800)
tests/run/cpp_templates.pyx

index 118dfa08082ed4ca6550108e62c7e6e057493831..11944a5359d1804377f74d08f00436333eb491e2 100644 (file)
@@ -61,4 +61,33 @@ def test_pair(int i, double x):
     finally:
         del pair
 
+def test_ptr(int i):
+    """
+    >>> test_ptr(3)
+    3
+    >>> test_ptr(5)
+    5
+    """
+    cdef Wrap[int*] *w
+    try:
+        w = new Wrap[int*](&i)
+        return deref(w.get())
+    finally:
+        del w
+
+cdef double f(double x):
+    return x*x
 
+def test_func_ptr(double x):
+    """
+    >>> test_func_ptr(3)
+    9.0
+    >>> test_func_ptr(-1.5)
+    2.25
+    """
+    cdef Wrap[double (*)(double)] *w
+    try:
+        w = new Wrap[double (*)(double)](&f)
+        return w.get()(x)
+    finally:
+        del w