May 15, 2015
On 5/14/15 11:22 PM, rcorre wrote:
> On Thursday, 14 May 2015 at 18:44:58 UTC, Steven Schveighoffer wrote:
>
>> It depends on the guts of MyContainer.Range.
>>
>> I'm assuming MyContainer.Range has SOME sort of references (i.e.
>> pointers) to the data in the container, so why not just have:
>>
>> bool empty() { return someRef == null || yourCurrentTest; }
>>
>
> In this case, I want to return an empty range when the container
> instance itself is null. I could have a static method
> MyContainer.emptySlice, but I feel like I've seen this general situation
> crop up a lot with small variations.

I'd have to see the code, but it seems like your situation is different from what I think, or you are not understanding what I'm saying :)

As an example:

struct MyContainer
{
  private int[] data;
  struct Range
  {
     private int *curData;
     private int *endOfData;
     int front() { return *curData; }
     bool empty() { return curData == endOfData; }
     void popFront() { ++curData; }
  }

  Range opSlice() {return Range(data.ptr, data.ptr + data.length);}
}

Range.init would be a valid empty range in this case. But I have no idea what your situation is. That's why I said it depends on the guts of the Range.

-Steve
May 17, 2015
On Friday, 15 May 2015 at 03:47:46 UTC, rcorre wrote:
> On Friday, 15 May 2015 at 03:22:43 UTC, rcorre wrote:
>> On Thursday, 14 May 2015 at 14:57:26 UTC, Idan Arye wrote:
>>
>>> How about a more flexible solution?
>>>
>>> http://dpaste.dzfl.pl/2f99cc270651
>>
>> Neat, thanks!
>>
>
> The range I don't pick may be an expression that would fail, so I tweaked it to:
> SelectRange!T selectRange(T...)(size_t index, lazy T ranges)
>
> Other than that, it seems to be just what I needed. Thanks again!

Keep in mind that lazy arguments are actually delegates, which means they need the GC. If using the GC doesn't bother you you can use std.range.interfaces to wrap things up in an object: http://dlang.org/phobos/std_range_interfaces.html#InputRange
1 2
Next ›   Last »