On 05/01/2011 08:04 AM, Dmitry Olshansky wrote:
On 01.05.2011 18:30, Andrej Mitrovic wrote:
I'm not sure how to use those wrappers though. Maybe I'm just doing it
wrong:

http://codepad.org/eHIdhasc

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.
Well, this compiles, you just need to pick suitable type of range
'interface', that's the subtle thingie:
http://codepad.org/uE0nIwbk

To make it more convenient to other, I paste Dmitry Olshansky's code:

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

enum BufferSize = 10;

struct Work
{
    private float[BufferSize] _buffer;
    RandomAccessInfinite!(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(){}

I also paste the compilation output:

Line 6: enum declaration is invalid
Line 6: Declaration expected, not '='
Line 13: semicolon expected following function declaration
Line 13: Declaration expected, not '('
Line 17: no identifier for declarator buffer
Line 24: unrecognized declaration


Limitations are caused by bug, that is going to get fixed eventually ;)


Ali

Reply via email to