Debian Codegraph @

gcc/testsuite/gdc.test/compilable/test11824.d

raw
1 // REQUIRED_ARGS: -o-
2 // PERMUTE_ARGS:
3
4 struct Take(R)
5 {
6 public R source;
7 private size_t _maxAvailable;
8
9 alias R Source;
10
11 @property bool empty()
12 {
13 return _maxAvailable == 0 || source.empty;
14 }
15
16 @property auto ref front()
17 {
18 return source.front;
19 }
20
21 void popFront()
22 {
23 source.popFront();
24 --_maxAvailable;
25 }
26
27 @property size_t length() const
28 {
29 return _maxAvailable;
30 }
31 }
32
33 struct Repeat(T)
34 {
35 private T _value;
36
37 enum bool empty = false;
38 @property inout(T) front() inout { return _value; }
39 void popFront() {}
40 }
41
42 Take!(Repeat!T) repeat(T)(T value, size_t n)
43 {
44 return typeof(return)(Repeat!T(value), n);
45 }
46
47 auto array(Range)(Range r)
48 {
49 alias E = typeof(r.front);
50 //static if (hasLength!Range)
51 {
52 if (r.length == 0)
53 return null;
54
55 auto result = new E[](r.length);
56
57 size_t i;
58 static auto trustedGetAddr(T)(ref T t) @trusted nothrow pure
59 {
60 return &t;
61 }
62 foreach (e; r)
63 {
64 *trustedGetAddr(result[i]) = e;
65 ++i;
66 }
67 return cast(E[])result;
68 }
69 }
70
71 enum r = [1].repeat(1).array;
72 static assert(r == [[1]]);