File: ifti.d

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (116 lines) | stat: -rw-r--r-- 2,915 bytes parent folder | download | duplicates (3)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
extern (C) int printf(const scope char*, ...);

struct S {
    int x = 3;
    void fun(T)(T x) { printf("S.fun(%s)(%d)\n", T.stringof.ptr, x); this.x += x; }
}

class Tst(TST, int v = 2) {
    int x = 3;
    int z = 4;

    final private void proc(int x) { printf("proc(%d) -> %d\n", x, this.x); }
    void fun(T)(T x) { printf("fun(%s)(%d) -> %d\n", T.stringof.ptr, x, this.x);}
    void fun()() { printf("fun()() -> %d\n", this.x); }
    void fun2()() { printf("fun2\n"); }

    class Inner {
        int y = 99;
        Tst outer;
        void f3() { z = 55; }
        // Make sure the correct this-ptr is used
        void f1() { printf("Inner.f1\n"); proc(-11); outer.proc(-11); }
        void f2() { printf("Inner.f2\n"); fun(-17); outer.fun(-17); }
    }
    Inner inner;

    this() {
        inner = new Inner;
        inner.outer = this;
    }

    void callInnerf1() { printf("callInnerf1\n"); inner.f1(); }
    void callInnerf2() { printf("callInnerf2\n"); inner.f2(); }


//
    void opBinary(string op : "+", T)(T x) { this.x += x; printf("opAdd(%d)\n", x); }
    void opUnary(string op : "+")() { printf("opPos()\n"); }
    //void opPos() { printf("xxx"); }
    void opIndex(T)(T x) { printf("opIndex[%d]\n",x); }

    void opIndex(A,B,C)(A a, B b, C c) {
        printf("opIndex[(%s) %d, (%s) %d, (%s) %d]\n", A.stringof.ptr, a,
                 B.stringof.ptr,b,C.stringof.ptr,c);
    }

    static if (v > 1) {
        void opCall(A = int, B = float)(A a = 1, B b = 8.2) { printf("opCall(%d, %d)\n",a,b); this.x++; }
    }
    void opSlice(A,B)(A a, B b) { printf("opSlice(%d, %d)\n",a,b); }
    void opSlice()() { printf("opSlice()\n"); }

    void opIndexAssign(A,B)(A a, B b) {
        printf("opIndexAssign((%s) %d, (%s) %d)\n", A.stringof.ptr, a, B.stringof.ptr, b);
    }

    void opSliceAssign(A,B,C)(A a, B b, C c) {
        printf("opSliceAssign(%.s, %d, %d)\n", a.length, a.ptr, b, c);
    }

    bool opEquals(A)(A x) { printf("opEquals((%s))\n", A.stringof.ptr); return true; }

    int opApply(T)(int delegate(ref T)dg) {
        for (int i = 0; i < 5; i++) {
            T d = cast(T)(i+0.1);
            if (auto result = dg(d))
                return result;
        }
        return 0;
    }
}

class Y : Tst!(float) {}

void main() {
    Tst!(int) t = new Tst!(int);
    Y u = new Y;
    S s;
    t.x = 7;
    t.proc(5);
    t.fun(5);
    t.fun();
    t.callInnerf1();
    t.callInnerf2();
    u.fun(5);
    u.fun();
    u.callInnerf1();
    u.callInnerf2();
    s.fun(5);
    t.fun2();

    +t;
    t+5;
    t[55];
    t[1,2,3.0];
    u[1,2,3.0];
    t(1,2.5);
    t(2);
    t();
    t[];
    t[1..2];
    u[1..2.5];
    t == t;
    auto b = t != t; // without assignment -> "! has no effect in expression"
    t == u;
    u == t;
    u == u;
    b = u != u;
    foreach(int i;t) {
        printf("%d\n", i);
    }
    foreach(double i;t) {
        printf("%g\n", i);
    }

}