Re: Using arrays with functions taking ranges

2012-12-14 Thread monarch_dodra
On Friday, 14 December 2012 at 15:59:48 UTC, Mu wrote: It works because "put" is defined for all input ranges as "write to first element and popFront". That makes more sense, thanks. So what happens is that for "regular" ranges std.range.put() gets used, while for arrays in RefAppender std.arr

Re: Using arrays with functions taking ranges

2012-12-14 Thread Mu
It works because "put" is defined for all input ranges as "write to first element and popFront". That makes more sense, thanks. So what happens is that for "regular" ranges std.range.put() gets used, while for arrays in RefAppender std.array.put() gets used, right? (I noticed that the unitte

Re: Using arrays with functions taking ranges

2012-12-14 Thread monarch_dodra
On Friday, 14 December 2012 at 14:56:45 UTC, Mu wrote: It "works" because in theory, all mutable ranges verify the "is output range" trait. However, they are not "sinks", so if you write too much into them, you'll get an out of index exception. Does it work at runtime, and do you get the correc

Re: Using arrays with functions taking ranges

2012-12-14 Thread Mu
It "works" because in theory, all mutable ranges verify the "is output range" trait. However, they are not "sinks", so if you write too much into them, you'll get an out of index exception. Does it work at runtime, and do you get the correct behavior? From what I tested, yes it works correctly

Re: Using arrays with functions taking ranges

2012-12-14 Thread monarch_dodra
On Friday, 14 December 2012 at 13:09:15 UTC, Mu wrote: Thank you, monarch_dodra. This looks like what I wanted. I have a question: How come the function works with MmFile.opSlice's without appender(&)? And is this reliable behavior? caesarCipher(cast(ubyte[]) inputFile.opSlice, cast(ubyte[])

Re: Using arrays with functions taking ranges

2012-12-14 Thread Mu
Thank you, monarch_dodra. This looks like what I wanted. I have a question: How come the function works with MmFile.opSlice's without appender(&)? And is this reliable behavior? caesarCipher(cast(ubyte[]) inputFile.opSlice, cast(ubyte[]) outputFile.opSlice, 13); Trying to use appender(&) on

Re: Using arrays with functions taking ranges

2012-12-14 Thread monarch_dodra
On Friday, 14 December 2012 at 10:20:38 UTC, Mu wrote: Thank you for your suggestion, bearophile. I ended up checking if the range is empty, and if it was, I'd increment it as elements were added. Honestly, I much dislike this method. It does not feel right. The C++ version is more consistent

Re: Using arrays with functions taking ranges

2012-12-14 Thread Mu
Thank you for your suggestion, bearophile. I ended up checking if the range is empty, and if it was, I'd increment it as elements were added. Honestly, I much dislike this method. It does not feel right. The C++ version is more consistent because of the iterators. Please, if anyone has a bet

Re: Using arrays with functions taking ranges

2012-12-13 Thread bearophile
Mu: Then how can I approach this to work for both cases: 1) output is empty? 2) output is the size of input? (MmFile's) You have to tell those cases apart with a run time test, so your output range should support empty, or even length. If you want to overwrite the already allocated space, t

Re: Using arrays with functions taking ranges

2012-12-13 Thread Mu
foreach (i, ref o; output) But isn't output empty? Indeed it is, when output is a new array. Then how can I approach this to work for both cases: 1) output is empty? 2) output is the size of input? (MmFile's)

Re: Using arrays with functions taking ranges

2012-12-13 Thread bearophile
Mu: foreach (i, ref o; output) But isn't output empty? Bye, bearophile

Using arrays with functions taking ranges

2012-12-13 Thread Mu
The code below works as is with memory mapped files' casted opSlice's. However, I can't figure out how to test it with simple arrays. Its unittest fails. Question: How to implement the function correctly? Otherwise what is the correct way to test it? Thank you. Code: Range2 c