| 1 |
@safe unittest |
| 2 |
{ |
| 3 |
import std.range.interfaces; |
| 4 |
|
| 5 |
import std.algorithm.iteration : map; |
| 6 |
import std.range : iota; |
| 7 |
|
| 8 |
void useRange(InputRange!int range) { |
| 9 |
// Function body. |
| 10 |
} |
| 11 |
|
| 12 |
// Create a range type. |
| 13 |
auto squares = map!"a * a"(iota(10)); |
| 14 |
|
| 15 |
// Wrap it in an interface. |
| 16 |
auto squaresWrapped = inputRangeObject(squares); |
| 17 |
|
| 18 |
// Use it. |
| 19 |
useRange(squaresWrapped); |
| 20 |
} |
| 21 |
|
| 22 |
@safe unittest |
| 23 |
{ |
| 24 |
import std.range.interfaces; |
| 25 |
|
| 26 |
import std.array; |
| 27 |
auto app = appender!(uint[])(); |
| 28 |
auto appWrapped = outputRangeObject!(uint, uint[])(app); |
| 29 |
static assert(is(typeof(appWrapped) : OutputRange!(uint[]))); |
| 30 |
static assert(is(typeof(appWrapped) : OutputRange!(uint))); |
| 31 |
} |
| 32 |
|