<div class="gmail_quote">On Sun, May 30, 2010 at 15:48, Andrei Alexandrescu <span dir="ltr">&lt;<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br></div><div class="im">
Will the definition of a forward range change to incorporate save, or do<br>
you intend to distinguish ranges that can do<br>
<br>
     R r2 = r1;<br>
and those that have:<br>
     auto r2 = r1.save;<br>
?<br>
Until now, they were one and the same to me.<br>
</div></blockquote><br>
<br>
Yah. Essentially R r2 = r1; is not a guarantee that r2 is independent from r1. (The obvious case: R is a class or interface type.) You&#39;ll need to call R r2 = r1.save; to make sure that now you have two independently-moving ranges. So yes, save must be a member of all forward ranges. isForwardRange will yield false if it doesn&#39;t find save.<br>
</blockquote><div><br><br>OK, understood.<br> </div><div><br><br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">      <br></div></blockquote>
An input range can be initialized from another input range, with the mention that it doesn&#39;t leave the original range independent from the copy. So Map works as it is.<br><div class="im"></div></blockquote><div><br>OK, so map(intputRange) could be affected after its creation by any modification to inputRange, that&#39;s coherent. I don&#39;t think I was ever confronted to this situation. I tend to discard ranges as I compose them.<br>
<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im"></div>
Lazy and input ranges are not incompatible.<br></blockquote><div><br>I see that now. I really thought that a = b was a no-no for input ranges.<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br>
    // at module scope<br>
    void swapFront(Range)(Range r1, Range r2)<br>
    {<br>
        static if (is(typeof(&amp;(r1.front)) == ElementType!(Range)*)) {<br>
            swap(r1.front, r2.front);<br>
        } else {<br>
            static assert(is(typeof(&amp;(r1.swapFront)), &quot;Cannot swap ranges&quot;);<br>
            r1.swapFront(r2);<br>
        }<br>
    }<br>
<br>
<br></div><div class="im">
OK. I really like this possibility to test for members and activate them<br>
when possible. Maybe it could be abstracted away into a Select-like<br>
template?<br>
</div></blockquote>
<br>
More detail please.<br></blockquote><div><br>It&#39;s just that my code is full of these static ifs. They are clear but I&#39;d like two things:<br><br><br>IfPossible!(someCode);            // static if (is( typeof())) or __traits(compiles, someCode), then someCode. It&#39;s becoming  a chore to repeat twice the same line.<br>
<br><br>and:<br><br><br>ConditionalCode!(cond1, code1,       // static if cond1 then code1<br>                                   cond2, code2,      // else static if cond2 then code2<br>...<br>                                   optionalDefaultCode);<br>
<br><br>But I have no solution except by using q{} strings... Maybe with lazy void()?<br><br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
OK. So it&#39;s really sameFront and not equalFront or somesuch.<br>
</div></blockquote><br>
<br>
Yah. A previous attempt at naming was sameHead but I don&#39;t want to add too many notions.<br></blockquote><div><br>Out of curiosity, what algorithm did you have in mind?<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
</div><div class="im">
I was thinking of frustrating obstacles like:<br>
<br>
auto m = map!&quot;a*a&quot;([0,1,2,3]);<br>
auto c = cycle(m); // won&#39;t compile, m.front is not an lvalue, whereas<br>
c.front asks for one.<br>
<br></div><div class="im">
Putting auto ref front() {...} in Cycle does not change anything. Too bad.<br>
</div></blockquote><br>
<br>
That&#39;s a bug in the compiler.<br></blockquote><div><br>I&#39;ll see if I can obtain a simple example and put it in bugzilla, then.<br><br><br></div></div>