Lots of low hanging fruit in Phobos

Adam D. Ruppe destructionator at gmail.com
Fri Mar 7 18:44:54 PST 2014


On Saturday, 8 March 2014 at 02:15:19 UTC, Adam D. Ruppe wrote:
> I guess the whole yield thing can be kinda nice, I'm just not 
> sure it is that big of a win given its other limitations 
> compared to full ranges.

I slapped this together to see if we can do it with a mixin 
template:

http://arsdnet.net/dcode/next.d

struct ShortRange {
	int next() {
		switch(callNumber) {
			case 0: return 50;
			case 1: return 60;
			case 2: return 70;
			case 3: return finished();
			default: assert(0);
		}
	}

	mixin MakeShortRange!();
}

Wordier than
yield ShortRange() { yield 50; yield 60; yield 70; }

but the same idea. (In fact, i'm sure the whole yield thing 
should pretty much just rewrite into something like this anyway).

My hypothetical from the previous post would be written:


struct ShortRange {
         Result result;
         this(string s) {
             result = c_query(s);
         }
	Row next() {
              if(!HasRow(result))
                  return finished();
              return GetNextRow(result);
	}

	mixin MakeShortRange!();
}

Which is a bit shorter and perhaps nicer to use than the long 
form range.


More information about the Digitalmars-d mailing list