|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.learn - Three questions on std.range
Hello,
Just get to my point to save time:
1.retro:
void testRetro()
{
int[] arr=[1,2,3,4,5];
auto retArr=retro(arr);
for(int i=0;i<retArr;i++)
writef("%d ",retArr[i]);
}
void main()
{
testRetro;
}
output:
0 0 5 4 3 //not 5 4 3 2 1 ?what's wrong here?
2.Continue to #1,In the source:
static if (isRandomAccessRange!(R) && hasLength!(R))
ref ElementType!(R) opIndex(uint n)
{
return _input[_input.length - n + 1];
}
Per my understanding,the above will return the nth element of _input in reverse
order. I try to count my fingers with length-n+1 but cannot get a correct
result.
3. About isInfinte:
template isInfinite(Range)
{
static if (isInputRange!(Range) && is(char[1 + Range.empty]))
enum bool isInfinite = !Range.empty;
else
enum bool isInfinite = false;
}
In the is expression is(char[1+ Range.empty]),below is my understanding;
Step 1:
is(char[1+Range.empty]) actually returns is(char[1+Range.empty?0:1])
Step 2:
But what does this help with determining whether Range is infinite or not?say
char[1+0],char[1+1]?
Any help would be much much appreciated.
Regards,
Sam
Jun 16 2009
On Wed, 17 Jun 2009 00:04:51 -0400, Sam Hu <samhudotsamhu gmail.com> wrote: Jun 17 2009
Max Samukha Wrote:3. This is a (hackish) way to detect if Range.empty's value is statically known. Infinite ranges must define a boolean 'empty' member that evaluates at compile time to false. Probably, there should be a more generic way to do it. Something like isCT(alias expression) template. I kinda have one but it doesn't work in all cases due to a compiler bug. Jun 17 2009
On Wed, 17 Jun 2009 00:04:51 -0400, Sam Hu <samhudotsamhu gmail.com> wrote: Jun 17 2009
|