Why ByChunk is not regnize by st.range.takeOne and why Section has no value

bioinfornatics via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 3 13:45:28 PST 2014


On Monday, 3 November 2014 at 21:03:51 UTC, bioinfornatics wrote:
> On Monday, 3 November 2014 at 06:43:50 UTC, Ali Çehreli wrote:
>> On 11/02/2014 04:58 PM, bioinfornatics wrote:
>>
>> > Dear,
>> > Some problem to build this code:
>> http://fpaste.org/147327/75948141/
>> >
>> >
>> > $ ldc2 fasta_test.d
>> > /usr/include/d/std/range.d(3605): Error: template
>> std.array.save
>> > cannot deduce function from argument types !()(ByChunk),
>> > candidates are:
>>
>> I think that is due to the too permissive template constraint 
>> of takeOne in phobos/std/range.d. Even though it say 
>> "isInputRange!R", it clearly needs "isForwardRange!R" because 
>> it calls .save() on that range:
>>
>>    @property auto save() { return Result(_source.save, empty); 
>> }
>>
>> So, the following is wrong:
>>
>>  auto takeOne(R)(R source) if (isInputRange!R)
>>
>> It should be:
>>
>>  auto takeOne(R)(R source) if (isForwardRange!R)
>>
>> If you modify range.d locally to require ForwardRange, you 
>> will see that your following call will get an error message 
>> because byChunk is not a ForwardRange:
>>
>>        // Take a piece of byte from current file
>>        ubyte[] buffer =  takeOne(inputRange);
>>
>> I think this issue is already reported as a part of the 
>> following bug:
>>
>>  https://issues.dlang.org/show_bug.cgi?id=9724
>>
>> Ali
>
> Ok but I do not see why to use save method for a takeOne 
> function
> is possible to write this function without to use it

Example:

auto takeOne(R)(ref R source) if (isInputRange!R)
{
      static if (hasSlicing!R)
      {
          return source[0 .. !source.empty];
      }
      else
      {
          typeof(R.front) r;
          if(!source.empty){
              r = source.front;
              source.popFront();
          }

          return r;
      }
}


More information about the Digitalmars-d-learn mailing list