getNext

Mehrdad wfunction at hotmail.com
Mon Jul 9 09:05:21 PDT 2012


> With your design you need to add something extra to allow 
> writing to elements of a single-pass range.

If that's the case, I'd hate to tell you this, but _unless_
you're planning on removing the notion of input/output ranges
(and perhaps adding single-pass/multi-pass), you're doing it
wrong. :-)

That capability is simply /not needed/ when your /only/ contract
is that something is an input range.

Asking an input range, "hey, can I write to you?" is just...
insulting!
That's like asking an electrical engineer if he can plumb.

Sure, it might come in handy if he can, but it's just plain silly
to ask himi that. If you need someone who can do both, then ask
for someone who's an EE _and_ a plumber.

On the other hand, the concepts of single-pass and multi-pass are
most certainly NOT orthogonal, for obvious reasons. So it DOES
make sense to ask an output range, "hey, can I write to you
multiple times?"

So if you're expecting to be able to say

	void foo(R)(ref R range) if (isInputRange!R)
	{
		static if (hasLValueElements!R)  // or whatever it was
			range.front = (ElementType!R).init;
	}

then you're mixing up two completely unrelated/orthogonal
concepts, which is silly.

What you SHOULD be saying instead is:

	void foo(R)(ref R range) if (isInputRange!R)
	{
		static if (isOutputRange!R)  // or whatever it was
			range.put((ElementType!R).init);
	}



More information about the Digitalmars-d mailing list