The type to be tested.
$(D_KEYWORD true) if R supports slicing, $(D_KEYWORD false) otherwise.
1 static assert(hasSlicing!(int[])); 2 static assert(hasSlicing!(const(int)[])); 3 static assert(hasSlicing!(dstring)); 4 static assert(hasSlicing!(string)); 5 static assert(!hasSlicing!(const int[])); 6 static assert(!hasSlicing!(void[])); 7 8 struct A 9 { 10 int front() @nogc nothrow pure @safe 11 { 12 return 0; 13 } 14 void popFront() @nogc nothrow pure @safe 15 { 16 } 17 bool empty() const @nogc nothrow pure @safe 18 { 19 return false; 20 } 21 typeof(this) save() @nogc nothrow pure @safe 22 { 23 return this; 24 } 25 @property size_t length() const @nogc nothrow pure @safe 26 { 27 return 0; 28 } 29 typeof(this) opSlice(const size_t i, const size_t j) 30 pure nothrow @safe @nogc 31 { 32 return this; 33 } 34 } 35 static assert(hasSlicing!A); 36 37 struct B 38 { 39 struct Dollar 40 { 41 } 42 int front() @nogc nothrow pure @safe 43 { 44 return 0; 45 } 46 void popFront() @nogc nothrow pure @safe 47 { 48 } 49 bool empty() const @nogc nothrow pure @safe 50 { 51 return false; 52 } 53 typeof(this) save() @nogc nothrow pure @safe 54 { 55 return this; 56 } 57 @property size_t length() const @nogc nothrow pure @safe 58 { 59 return 0; 60 } 61 @property Dollar opDollar() const @nogc nothrow pure @safe 62 { 63 return Dollar(); 64 } 65 typeof(this) opSlice(const size_t i, const Dollar j) 66 pure nothrow @safe @nogc 67 { 68 return this; 69 } 70 } 71 static assert(!hasSlicing!B); 72 73 struct C 74 { 75 int front() @nogc nothrow pure @safe 76 { 77 return 0; 78 } 79 void popFront() @nogc nothrow pure @safe 80 { 81 } 82 enum bool empty = false; 83 typeof(this) save() @nogc nothrow pure @safe 84 { 85 return this; 86 } 87 typeof(this) opSlice(const size_t i, const size_t j) 88 pure nothrow @safe @nogc 89 { 90 return this; 91 } 92 } 93 static assert(!hasSlicing!C); 94 95 struct D 96 { 97 struct Range 98 { 99 int front() @nogc nothrow pure @safe 100 { 101 return 0; 102 } 103 void popFront() @nogc nothrow pure @safe 104 { 105 } 106 bool empty() const @nogc nothrow pure @safe 107 { 108 return true; 109 } 110 typeof(this) save() @nogc nothrow pure @safe 111 { 112 return this; 113 } 114 @property size_t length() const @nogc nothrow pure @safe 115 { 116 return 0; 117 } 118 } 119 int front() @nogc nothrow pure @safe 120 { 121 return 0; 122 } 123 void popFront() @nogc nothrow pure @safe 124 { 125 } 126 enum bool empty = false; 127 typeof(this) save() @nogc nothrow pure @safe 128 { 129 return this; 130 } 131 Range opSlice(const size_t i, const size_t j) 132 pure nothrow @safe @nogc 133 { 134 return Range(); 135 } 136 } 137 static assert(hasSlicing!D);
Determines whether R is a forward range with slicing support (R[i .. j]).
For finite ranges, the result of opSlice() must be of the same type as the original range. If the range defines opDollar, it must support subtraction.
For infinite ranges, the result of opSlice() must be of the same type as the original range only if it defines opDollar(). Otherwise it can be any forward range.
For both finite and infinite ranges, the result of opSlice() must have length.