First, 1..23 isn't a range -- it's just special syntax that works only inside foreach statements.
A range that does the same as 1..23 is iota(1, 23) from std.range; it returns a range of successive values (such as integers).
To pass a range into a function, you generally want to use templates:
void foo(Range)(Range r)
{
foreach (e; r)
writeln(e);
}
Which you can then call the way you want:
foo(iota(1, 23)); // print the numbers from 1 to 23 (exclusive)
Note: if arr is an array, and you want a range of the values at indices 1..23 then you can use a slice:
foo(arr[1..23]);
A slice of an array is a range.
To have a function accept this, you don't need to use templates. foo could be written:
void foo(int[] r)
{
foreach (e; r)
writeln(e);
}
auto arr[22] = ...is not valid D code. - DejanLekicfoo(arr, 1..23)but you can dofoo(arr, iota(1, 23))or similar... - DejanLekic