RefRange

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 13 21:13:44 PDT 2012


I ran into a situation where I needed a forward range which was not a 
reference type to be consumed by a range-based function. Input ranges and 
reference type forward ranges are automatically and unavoidably consumed by 
range-based functions (assuming that save isn't called on them before the 
function starts consuming them), but that doesn't happen for either value type 
ranges or arrays. Hence my wrapper type (called RefRange). The code is here:

http://codepad.org/nNB4mAdN

I was wondering what other people's take on it was and whether I missed 
something which makes it a bad idea. Essentially, it's a range with a pointer 
to the original range so that any function calls on the wrapper affect the 
original range (and vice versa).

Assuming that no one pokes a major hole in it, and others think that it's a 
worthwhile addition, I'll create a pull request for it to be added to 
std.range. But I'd like other people's feedback on it first.

- Jonathan M Davis


More information about the Digitalmars-d mailing list