<div class="gmail_quote">On Mon, Mar 1, 2010 at 22:51, Lars T. Kyllingstad <span dir="ltr"><public@kyllingen.nospamnet></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;">
<div><div></div><div class="h5">Paul D. Anderson wrote:<br></div></div></blockquote><div>from std.range <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><div class="h5">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
"r.put(e) puts e in the range (in a range-dependent manner) and advances to the popFront position in the range. Successive calls to r.put add elements to the range. put may throw to signal failure."<br>
</blockquote></div></div></blockquote><div> with std.array.put:</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div class="h5"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
It modifies a[0] and then replaces the array with the tail of the array,<br>
omitting the first element.<br></blockquote></div></div></blockquote><div><br>It seems to me array.put does what the description in std.range entails.<br><br>I had the same reaction when reading array.put for the first time. How can a function putting values in something make them non-accessible at the same
time? But that's because for arrays the container and the associated range (view) are the same, leading to some confusion. put puts values not in the range as said in std.range but in the container accessed by the range. The range itself updates in the only way a range can: by shrinking (so, popFront), giving you a new place to put a another value.<br>
<br>As Lars said, a classical use would be:<br><br>Container c = new Container(values);<br>auto view =c.asOutputRange(); // view is an output range. Andrei suggested '.all' as a property returning a range on all values. <br>
<br>foreach(elem; view) view.put(someOtherValues); // writes values in c, consumes view.<br>assert(view.empty); // Now view is exhausted and c contains someOtherValues.<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><div class="h5"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
It's possible there is some arcane meaning to the word "put" that I'm not aware of, but if it means "insert an element at the front of the range" then std.array.put is wrongly implemented.<br>
<br></blockquote></div></div></blockquote><div><br>For some ranges, you can replace the front value:<br><br>
range.front = someValue;<br><br>But then, how would you go putting some more?<br>You cannot extend a range, I think. You can create a new range chaining new values and the old range, but that creates a new one.<br>auto prepended = chain(newValues, oldValues);<br>
<br>I think I have somewhere something inspired by zippers (<a href="http://en.wikipedia.org/wiki/Zipper_%28data_structure%29">http://en.wikipedia.org/wiki/Zipper_%28data_structure%29</a>), where a range 'remembers' previous values (stores them in an array) and you can make the front retreat, giving access to old values anew. But it cannot modify the sublying container, only the values stored (artificially) in the range. It's useful for some algorithms that need to go back and forth on a few positions.<br>
<br><br>Philippe<br><br><br></div></div>