On Tue, 12 Mar 2013 12:16:10 -0400, Andrei Alexandrescu <[email protected]> wrote:

On 3/12/13 11:47 AM, Steven Schveighoffer wrote:
On Tue, 12 Mar 2013 11:25:54 -0400, deadalnix <[email protected]> wrote:

On Tuesday, 12 March 2013 at 10:49:57 UTC, monarch_dodra wrote:

Having "isInfinite" can also have the advantage of protecting users
from stupid calls. For example, calling "count" on an infinite range
is forbidden => shifting problems from runtime to compile time is a
HUGE gain.


Clearly this is a good point. I however think that a static assert
within count is much better because it allow to give nicer feedback.
The problem with InfiniteRange is that it does gives you cryptic error
message like the count function do not exists.


Hm... is there a way to test for inifinitness without requiring to be an
enum?

Wouldn't this also be valid?

if(!R.init.empty)

Essentially, you can evaluate R.init.empty at compile time AND it's
false on an uninitialized range. How can a correctly written
non-infinite range pass that?

That would make forwarding much easier, as the 'dumb' implementation
still would result in an infinite range.

Crossed my mind a few times that fresh non-infinite ranges should be empty. But there's no explicit requirement stating that, and I think e.g. one may define a k-elements buffer backed by in-situ storage.

So something like this:

struct R
{
  int[4] elems;
  int idx;
  int front() { return elems[idx];}
  void popFront() {++idx;}
  bool empty() {idx < elems.length;}
}

which would make this an infinite range by my measurement.  Crap.

How can we make wrapping ranges easier? I get the point that it's a pain in the ass in order to implement a wrapper for another range for things like isInfinite, and save. We need something in std.range that allows you to wrap such functions, like a nice mixin.

-Steve

Reply via email to