File: cpp_templates_helper.h

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (52 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (5)
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
49
50
51
52
template <typename T, typename S=T, typename U=T>
class Wrap {
    T value;
public:
    typedef S AltType;

    Wrap(T v) : value(v) { }
    void set(T v) { value = v; }
    T get(void) { return value; }
    bool operator==(Wrap<T> other) { return value == other.value; }

    S get_alt_type(void) { return (S) value; }
    void set_alt_type(S v) { value = (T) v; }

    U create(void) { return (U) value; }
    bool accept(U v) { return v == (U) value; }
};

template <class T1, class T2>
class Pair {
    T1 _first;
    T2 _second;
public:
    Pair() { }
    Pair(T1 u, T2 v) { _first = u; _second = v; }
    T1 first(void) { return _first; }
    T2 second(void) { return _second; }
    bool operator==(Pair<T1,T2> other) { return _first == other._first && _second == other._second; }
    bool operator!=(Pair<T1,T2> other) { return _first != other._first || _second != other._second; }
};

template <class T1, class T2>
class SuperClass {
public:
    SuperClass() {}
};

template <class T2, class T3>
class SubClass : public SuperClass<T2, T3> {
};

template <class T>
class Div {
public:
    static T half(T value) { return value / 2; }
};

template <class T1, class T2>
class BinaryAnd {
public:
    static T1 call(T1 x, T2 y) { return x & y; }
};