| 1 |
/* |
| 2 |
TEST_OUTPUT: |
| 3 |
--- |
| 4 |
fail_compilation/test8556.d(24): Error: template instance `test8556.Grab!(Circle!(uint[]))` does not match template declaration `Grab(Range)` |
| 5 |
with `Range = Circle!(uint[])` |
| 6 |
must satisfy the following constraint: |
| 7 |
` !isSliceable!Range` |
| 8 |
fail_compilation/test8556.d(55): Error: template instance `test8556.grab!(Circle!(uint[]))` error instantiating |
| 9 |
--- |
| 10 |
*/ |
| 11 |
|
| 12 |
extern(C) int printf(const char*, ...); |
| 13 |
|
| 14 |
template isSliceable(R) |
| 15 |
{ |
| 16 |
enum bool isSliceable = is(typeof( R.init[1 .. 2] )); |
| 17 |
} |
| 18 |
|
| 19 |
struct Grab(Range) if (!isSliceable!Range) |
| 20 |
{ |
| 21 |
public Range source; |
| 22 |
} |
| 23 |
|
| 24 |
Grab!R grab(R)(R input) |
| 25 |
{ |
| 26 |
return Grab!R(input); |
| 27 |
} |
| 28 |
|
| 29 |
// 3. evaluate isSliceable in template constraint |
| 30 |
auto grabExactly(R)(R range) if (!isSliceable!R) { return 0; } |
| 31 |
auto grabExactly(R)(R range) if ( isSliceable!R) { return 0; } |
| 32 |
|
| 33 |
struct Circle(Range) |
| 34 |
{ |
| 35 |
// 2. auto return opSlice |
| 36 |
auto opSlice(size_t i, size_t j) |
| 37 |
{ |
| 38 |
//pragma(msg, typeof(opSlice)); // prints "fwdref err" with B, but doesn't with A |
| 39 |
|
| 40 |
printf("%d %d\n", cast(int)i, cast(int)j); |
| 41 |
assert(j >= i); |
| 42 |
|
| 43 |
// 1. grabExactly curcular refers this opSlice. |
| 44 |
return grabExactly(typeof(this)()); // broken execution with A |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
Circle!R circle(R)() |
| 49 |
{ |
| 50 |
return Circle!R(); |
| 51 |
} |
| 52 |
|
| 53 |
void main() |
| 54 |
{ |
| 55 |
auto t = grab(circle!(uint[])()); |
| 56 |
|
| 57 |
auto cx = circle!(uint[])(); |
| 58 |
auto slice = cx[23 .. 33]; |
| 59 |
} |