Polymorphic ranges?

Ali Çehreli acehreli at yahoo.com
Sun May 1 21:31:25 PDT 2011


On 05/01/2011 07:30 AM, Andrej Mitrovic wrote:
> I'm not sure how to use those wrappers though. Maybe I'm just doing it wrong:
>
> http://codepad.org/eHIdhasc

To make it more convenient to others, I paste Andrej Mitrovic's code:

import std.stdio;
import std.range;
import core.thread;
import std.random;

enum BufferSize = 10;

struct Work
{
     private float[BufferSize] _buffer;
     InputRangeObject!(float[]) buffer;

     this(T)(T unused)
     {
         _buffer[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

         buffer = inputRangeObject(cycle(_buffer[]));
     }

     void setNewRange(size_t min, size_t max)
     {
         buffer = inputRangeObject(cycle(_buffer[min..max]));
     }
}

void main(){}

/*
Error: cannot implicitly convert expression
(inputRangeObject(cycle(this._buffer[min..max])))
of type std.range.InputRangeObject!(Cycle!(float[])).InputRangeObject
to std.range.InputRangeObject!(float[]).InputRangeObject
*/

>
> But it seems these wrappers have some problems, the docs say about the
> interfaces:
>
> Limitations:
> These interfaces are not capable of forwarding ref access to elements.
> Infiniteness of the wrapped range is not propagated.
> Length is not propagated in the case of non-random access ranges.

Ali



More information about the Digitalmars-d-learn mailing list