<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Mar 4, 2014, at 22:25, Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">I suspect that at a certain point (soon) those of us who feel strongly about this should sit down if possible and hash this out either over lunch, beers, or a whiteboard. =D</div>
<div class="gmail_quote"><br></div></div></div></div></blockquote><div><br></div><div>I'm in for beers, anyway!</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 4, 2014 at 9:26 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":38s" class="a3s" style="overflow:hidden">I agree. Algorithms should be verbs.<br>
<br>
However, I disagree that range adaptors are algorithms.<br>
<br>
“reverse” sounds like an algorithm. Consider, from the STL:<br>
<br>
template <class Iterator> void reverse(Iterator F, Iterator L);<br>
<br>
I’d expect a range version of the algorithm to look like this:<br>
<br>
template <class Range> void reverse(Range &R) {<br>
reverse(std::begin(R), std::end(R));<br>
}<br>
<br>
On the other hand, “reversed” sounds like an accessor, and I’d expect it to look something like this:</div></blockquote><div><br></div><div>I understand the point you're trying to make here, and how you would implement it, however I'm not persuaded this is the right design.</div>
<div><br></div></div></div></div></div></blockquote><div><br></div><div>Admittedly, I'm coming in with a Boost bias, having used that range library for years. </div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>First, while an in-place approach to the interface of range algorithms is one possibility, it has a fatal flaw: it is not composable. I want to be able to write something equivalent to "x = reverse(sort(slice(std::move(x), 1, 10)))" </div></div></div></div></div></blockquote><div><br></div><div>This is interesting. I hadn't considered r-value references with ranges. Is there a problem with supporting both semantics with the same names?</div><div><br></div><div> template <class Range> Range reverse(Range &&R);</div><div> template <class Range> void reverse(Range &R);</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>because this allows us to factor apart the different aspects of using ranges. It addresses the "<foo>_if" composition problem, the "<foo>_n" composition problem, etc. The solution requires us to bring value semantics to algorithms, what I think would be the best result of ranges in C++.<br>
</div><div><br></div><div>Second, I really don't want two different patterns, because I find it very hard to tell what is an algorithm and what isn't. Maybe "sliced" clearly isn't an algorithm, and "sort" clearly is, but "reversed" starts to blur the line. What about rotate? I have heard many argue that filter should be an accessor. If sort is an algorithm, than surely partition is. But partition is just the same as filter! I think it is all simpler if these all follow the same fundamental pattern.</div></div></div></div></div></blockquote><div><br></div><div>You're right, it needs to somehow be clear. I think one reasonable rule is "past participle" means adaptor, while "present tense" means algorithm. (That's why "reversed" makes some sense to me.) By that rule, I'd say reverse, filter and rotate are algorithms (mutating the input), but reversed, filtered and rotated are adaptors (providing a mutated view of the input). If we're consistent it'll be clear.</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div><br></div><div>Third, this is *exactly* what I mean that we don't yet know what ranges look like in C++. Whatever we end up with, I think we should be prepared to change it based on experience and based on the discussions that go on in the committee. My hope is that we can try out some of these approaches and, if they work, also contribute to that discussion.</div>
</div></div></div>
</div></blockquote><br><div>Agreed. </div></body></html>