How to return range constructs?

Dicebot public at dicebot.lv
Fri Feb 28 09:12:43 PST 2014


Looks like you are over-complicating things:

http://dpaste.dzfl.pl/eaca1408dc88

import std.range;

struct ColumnVectorForwardRange(T)
{
	private
	{
		T[] data;
		size_t cur = 0;
		size_t length = 0;
	}

	ColumnVectorForwardRange!T save() @property {
		return this;
	}

	bool empty() @property {
		return !length;
	}
	
	T front() @property {
		return data[cur];
	}
	
	void popFront() {
		++cur;
		--length;
	}
}

static assert(isForwardRange!(ColumnVectorForwardRange!int));

void main() {}


More information about the Digitalmars-d-learn mailing list