cython

Форк
0
/
cpp_stl_forward_list.pyx 
79 строк · 1.3 Кб
1
# mode: run
2
# tag: cpp, werror, cpp11, no-cpp-locals
3

4
from cython.operator cimport dereference as deref
5
from cython.operator cimport preincrement as incr
6

7
from libcpp.forward_list cimport forward_list
8
from libcpp cimport bool as cbool
9

10

11
def simple_iteration_test(L):
12
    """
13
    >>> iteration_test([1,2,4,8])
14
    8
15
    4
16
    2
17
    1
18
    >>> iteration_test([8,4,2,1])
19
    1
20
    2
21
    4
22
    8
23
    """
24
    cdef forward_list[int] l
25
    for a in L:
26
        l.push_front(a)
27
    for a in l:
28
        print(a)
29

30
def iteration_test(L):
31
    """
32
    >>> iteration_test([1,2,4,8])
33
    8
34
    4
35
    2
36
    1
37
    >>> iteration_test([8,4,2,1])
38
    1
39
    2
40
    4
41
    8
42
    """
43
    l = new forward_list[int]()
44
    try:
45
        for a in L:
46
            l.push_front(a)
47
        it = l.begin()
48
        while it != l.end():
49
            a = deref(it)
50
            incr(it)
51
            print(a)
52
    finally:
53
        del l
54

55
def test_value_type(x):
56
    """
57
    >>> test_value_type(2)
58
    2.0
59
    >>> test_value_type(2.5)
60
    2.5
61
    """
62
    cdef forward_list[double].value_type val = x
63
    return val
64

65
def test_value_type_complex(x):
66
    """
67
    >>> test_value_type_complex(2)
68
    (2+0j)
69
    """
70
    cdef forward_list[double complex].value_type val = x
71
    return val
72

73

74
#  Tests GitHub issue #1788.
75
cdef cppclass MyForwardList[T](forward_list):
76
    pass
77

78
cdef cppclass Ints(MyForwardList[int]):
79
    pass
80

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.