/usr/lib/gcc/x86_64-linux-gnu/5/include/d/std/internal/test/dummyrange.d is in libphobos-5-dev 5.5.0-12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | /**
For testing only.
Used with the dummy ranges for testing higher order ranges.
*/
module std.internal.test.dummyrange;
import std.typecons;
import std.typetuple;
import std.range.primitives;
enum RangeType
{
Input,
Forward,
Bidirectional,
Random
}
enum Length
{
Yes,
No
}
enum ReturnBy
{
Reference,
Value
}
// Range that's useful for testing other higher order ranges,
// can be parametrized with attributes. It just dumbs down an array of
// numbers 1..10.
struct DummyRange(ReturnBy _r, Length _l, RangeType _rt)
{
// These enums are so that the template params are visible outside
// this instantiation.
enum r = _r;
enum l = _l;
enum rt = _rt;
uint[] arr = [1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U];
void reinit()
{
// Workaround for DMD bug 4378
arr = [1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U];
}
void popFront()
{
arr = arr[1..$];
}
@property bool empty() const
{
return arr.length == 0;
}
static if(r == ReturnBy.Reference)
{
@property ref inout(uint) front() inout
{
return arr[0];
}
@property void front(uint val)
{
arr[0] = val;
}
}
else
{
@property uint front() const
{
return arr[0];
}
}
static if(rt >= RangeType.Forward)
{
@property typeof(this) save()
{
return this;
}
}
static if(rt >= RangeType.Bidirectional)
{
void popBack()
{
arr = arr[0..$ - 1];
}
static if(r == ReturnBy.Reference)
{
@property ref inout(uint) back() inout
{
return arr[$ - 1];
}
@property void back(uint val)
{
arr[$ - 1] = val;
}
}
else
{
@property uint back() const
{
return arr[$ - 1];
}
}
}
static if(rt >= RangeType.Random)
{
static if(r == ReturnBy.Reference)
{
ref inout(uint) opIndex(size_t index) inout
{
return arr[index];
}
void opIndexAssign(uint val, size_t index)
{
arr[index] = val;
}
}
else
{
uint opIndex(size_t index) const
{
return arr[index];
}
}
typeof(this) opSlice(size_t lower, size_t upper)
{
auto ret = this;
ret.arr = arr[lower..upper];
return ret;
}
}
static if(l == Length.Yes)
{
@property size_t length() const
{
return arr.length;
}
alias opDollar = length;
}
}
enum dummyLength = 10;
alias AllDummyRanges = TypeTuple!(
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Forward),
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Bidirectional),
DummyRange!(ReturnBy.Reference, Length.Yes, RangeType.Random),
DummyRange!(ReturnBy.Reference, Length.No, RangeType.Forward),
DummyRange!(ReturnBy.Reference, Length.No, RangeType.Bidirectional),
DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Input),
DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Forward),
DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Bidirectional),
DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Random),
DummyRange!(ReturnBy.Value, Length.No, RangeType.Input),
DummyRange!(ReturnBy.Value, Length.No, RangeType.Forward),
DummyRange!(ReturnBy.Value, Length.No, RangeType.Bidirectional)
);
/**
Tests whether forward, bidirectional and random access properties are
propagated properly from the base range(s) R to the higher order range
H. Useful in combination with DummyRange for testing several higher
order ranges.
*/
template propagatesRangeType(H, R...)
{
static if(allSatisfy!(isRandomAccessRange, R))
enum bool propagatesRangeType = isRandomAccessRange!H;
else static if(allSatisfy!(isBidirectionalRange, R))
enum bool propagatesRangeType = isBidirectionalRange!H;
else static if(allSatisfy!(isForwardRange, R))
enum bool propagatesRangeType = isForwardRange!H;
else
enum bool propagatesRangeType = isInputRange!H;
}
template propagatesLength(H, R...)
{
static if(allSatisfy!(hasLength, R))
enum bool propagatesLength = hasLength!H;
else
enum bool propagatesLength = !hasLength!H;
}
/**
Reference type input range
*/
class ReferenceInputRange(T)
{
import std.array : array;
this(Range)(Range r) if (isInputRange!Range) {_payload = array(r);}
final @property ref T front(){return _payload.front;}
final void popFront(){_payload.popFront();}
final @property bool empty(){return _payload.empty;}
protected T[] _payload;
}
/**
Reference forward range
*/
class ReferenceForwardRange(T) : ReferenceInputRange!T
{
this(Range)(Range r) if (isInputRange!Range) {super(r);}
final @property ReferenceForwardRange save()
{return new ReferenceForwardRange!T(_payload);}
}
//Infinite input range
class ReferenceInfiniteInputRange(T)
{
this(T first = T.init) {_val = first;}
final @property T front(){return _val;}
final void popFront(){++_val;}
enum bool empty = false;
protected T _val;
}
//Infinite forward range
class ReferenceInfiniteForwardRange(T) : ReferenceInfiniteInputRange!T
{
this(T first = T.init) {super(first);}
final @property ReferenceInfiniteForwardRange save()
{return new ReferenceInfiniteForwardRange!T(_val);}
}
|