On Monday, 9 July 2012 at 15:48:35 UTC, Andrei Alexandrescu wrote:
On 7/9/12 11:35 AM, Mehrdad wrote:
If something is both an input range and an output range, then sure, it can have that capability. But being able to write to something is
_orthogonal_ to whether you can read from it.

That is the case right now. The point is, with your design you need to add something extra to allow writing to elements of a single-pass range. So your design does not simplify things as much as it might seem.

Andrei

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 (isOutput!R)  // or whatever it was
                        range.put((ElementType!R).init);
        }

Reply via email to