File: testdefault_after_variadic.d

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (98 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download | duplicates (7)
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
/*
PERMUTE_ARGS:
*/

version (with_phobos) import std.conv : text;

struct Tuple(T...)
{
    T expand;
    alias expand this;
}

auto tuple(T...)(T t)
{
    return Tuple!T(t);
}

void fun0(U, T...)(U gold, int b_gold, T a, int b)
{
    assert(tuple(a) == gold);
    assert(b == b_gold);
}

void fun(U, T...)(U gold, T a, int b = 1)
{
    assert(tuple(a) == gold);
    assert(b == 1);
}

void fun2(U, V, T...)(U gold, V gold2, T a, string file = __FILE__, int line = __LINE__)
{
    assert(tuple(a) == gold);
    assert(tuple(file, line) == gold2);
}

void fun3(int[] gold, int[] a...)
{
    assert(gold == a);
}

void fun4(T...)(size_t length_gold, int b_gold, T a, int b = 1)
{
    assert(T.length == length_gold);
    assert(b == b_gold);
}

// Example in changelog
string log(T...)(T a, string file = __FILE__, int line = __LINE__)
{
    return text(file, ":", line, " ", a);
}

void fun_constraint(T...)(T a, string b = "bar") if (T.length == 1)
{
}

/+
NOTE: this is disallowed by the parser:
void fun5(int[] gold, int[] a ..., int b = 1)
{
    assert(gold==a);
    assert(b==1);
}
+/

void main()
{
    fun0(tuple(10), 7, 10, 7);

    fun(tuple());
    fun(tuple(10), 10);
    fun(tuple(10, 11), 10, 11);

    fun2(tuple(10), tuple(__FILE__, __LINE__), 10);

    fun3([1, 2, 3], 1, 2, 3);

    fun_constraint(1);
    assert(!__traits(compiles, fun_constraint(1, "baz")));

    version (with_phobos)
        assert(log(10, "abc") == text(__FILE__, ":", __LINE__, " 10abc"));

    // IFTI: `b` is always default-set
    fun4(0, 1);
    fun4(1, 1, 10);
    fun4(2, 1, 10, 11);

    // with explicit instantiation, and default-set `b`
    fun4!int(1, 1, 10);
    fun4!(int, int)(2, 1, 10, 11);

    // with explicit instantiation, and over-ridden `b`
    fun4!int(1, 100, 10, 100);
    fun4!(int, int)(2, 100, 10, 11, 100);

    // fun5([1,2,3], 1,2,3);
}