Generic range to read array or a file as a phobos range
bioinfornatics
bioinfornatics at fedoraproject.org
Sun Mar 17 11:36:16 PDT 2013
On Friday, 15 March 2013 at 16:40:26 UTC, Andrea Fontana wrote:
> On Friday, 15 March 2013 at 16:11:38 UTC, bioinfornatics wrote:
>> On Friday, 15 March 2013 at 14:40:17 UTC, Andrea Fontana wrote:
>>> On Friday, 15 March 2013 at 14:31:43 UTC, bioinfornatics
>>> wrote:
>>>> Dear,
>>>>
>>>> By using CTFE I try to get a generic range to read array or
>>>> a file as a phobos range. code hosted here:
>>>> http://dpaste.dzfl.pl/1f2bcf39
>>>>
>>>> that works fine for array but for a File instance .eof seem
>>>> to not return true a right time.
>>>>
>>>> Soemone could say what happen ?
>>>>
>>>> Thanks
>>>
>>> Have you tried to cache front() result and read next block on
>>> popFront()?
>>
>> that is ok. Just missed the \n the followed code should work
>> http://dpaste.dzfl.pl/1f2bcf39
>>
>> You are welcome to take it :)
>
> int[] a = [ 0, 1, 1, 2, 3, 5, 8 ];
> std.file.write("/tmp/filename", a);
>
> File f = File("/tmp/filename", "r");
> auto r = GenericRange!File(f,1);
>
> r.filter!"a.length > 0 && a[0] != 0"().writeln;
>
> output:
> [[0], [0], [0], [0], [0], [0]]
>
> but i think output expected is:
> [[1], [1], [2], [3], [5], [8]]
>
> Caching front() and reading buffer from popFront() did the
> trick for me.
As you said that do not works i update the code with some
unittest could you please to share your version ? you can use
fork from dpast -> http://dpaste.dzfl.pl/1f2bcf39e. Thanks
More information about the Digitalmars-d-learn
mailing list