Why does inputRangeObject fail to derive correctly for RandomAccessInfinite ranges?

D Lark dlark at example.com
Wed Jul 13 01:23:35 UTC 2022


This is slightly related to this issue I reported earlier: 
https://forum.dlang.org/post/wghdwxptjfcjwptnybhn@forum.dlang.org

Here's the snippet that captures what fails for me

```dlang
     import std.range: ElementType, isRandomAccessRange, 
inputRangeObject, sequence, MostDerivedInputRange, 
RandomAccessInfinite;

     auto seq = sequence!((a, n) => n);
     alias SeqType = typeof(seq);
     static assert(isRandomAccessRange!SeqType);

     static assert(is(MostDerivedInputRange!SeqType == 
RandomAccessInfinite!(ElementType!SeqType)));

     auto seqInputRange = seq.inputRangeObject;
     static assert(isRandomAccessRange!(typeof(seqInputRange))); 
// returns 'false'; I expect this to return 'true' as the most 
derived type of 'seq' is of 'RandomAccessInfinite' as 
demonstrated above

```
I am compiling using dmd v2.100.1

First, please can someone clarify if the behaviour I expect in 
the last line is consistent with the intention of the library?

I have poked around the source and I can see that the 
`InputRangeObject` (the object returned by `inputRangeObject` 
derives from the return type of the `MostDerivedInputRange` 
template, which as shown above returns the correct interface. 
However it seems that the implementation of `InputRangeObject` 
does not implement `enum bool empty = false` in the case of the 
`RandomAccessInfinite` ranges, which leads to the template 
`isRandomAccessRange` returning false.


More information about the Digitalmars-d-learn mailing list