summaryrefslogtreecommitdiff
path: root/tests/run/cpp_nested_templates.pyx
blob: e40860caa55a6b48cb0cbb6f352708c3c063b79f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# mode: run
# tag: cpp, werror

from cython.operator cimport dereference as deref

cdef extern from "cpp_templates_helper.h":
    cdef cppclass Wrap[T]:
        Wrap(T)
        void set(T)
        T get()
        bint operator==(Wrap[T])

    cdef cppclass Pair[T1,T2]:
        Pair(T1,T2)
        T1 first()
        T2 second()
        bint operator==(Pair[T1,T2])
        bint operator!=(Pair[T1,T2])

def test_wrap_pair(int i, double x):
    """
    >>> test_wrap_pair(1, 1.5)
    (1, 1.5, True)
    >>> test_wrap_pair(2, 2.25)
    (2, 2.25, True)
    """
    try:
        wrap = new Wrap[Pair[int, double]](Pair[int, double](i, x))
        return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap)
    finally:
        del wrap

def test_wrap_pair_pair(int i, int j, double x):
    """
    >>> test_wrap_pair_pair(1, 3, 1.5)
    (1, 3, 1.5, True)
    >>> test_wrap_pair_pair(2, 5, 2.25)
    (2, 5, 2.25, True)
    """
    try:
        wrap = new Wrap[Pair[int, Pair[int, double]]](
                        Pair[int, Pair[int, double]](i,Pair[int, double](j, x)))
        return (wrap.get().first(),
                wrap.get().second().first(),
                wrap.get().second().second(),
                deref(wrap) == deref(wrap))
    finally:
        del wrap