Duncan P. N. Exon Smith
2014-Mar-05 04:07 UTC
[LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
On 2014 Mar 2, at 22:27, Chandler Carruth <chandlerc at google.com> wrote:> > On Sun, Mar 2, 2014 at 10:13 PM, Saleem Abdulrasool <compnerd at compnerd.org> wrote: > On Sun, Mar 2, 2014 at 9:26 PM, Chris Lattner <sabre at nondot.org> wrote: > > On Mar 2, 2014, at 8:53 PM, Renato Golin <renato.golin at linaro.org> wrote: > > > On 3 March 2014 12:32, Pete Cooper <peter_cooper at apple.com> wrote: > >> Would those work with a foreach construct? Perhaps I forgot to mention that was what I'm trying to work out here. > >> > >> In example 3 I was wondering if we could define a method reverse(). We could use sfinae to wrap that around rbegin/rend if people like that style? > > > > Sorry, I was too terse... ;) > > > > If MF is a reverse_iterator, it'd just work, no? But to get the > > reverse iterator, I think reverse() would be the best general pattern, > > since you can adapt it to each container needs. > > I'm not aware of the prior art or standards are here, but I think that a global reverse() adapter is the way to go. Likewise, we should have a standard "enumerate()" adaptor like python. > > I definitely prefer the global adaptor pattern. As for prior art, I had played with it a bit, and came up with https://gist.github.com/compnerd/5694186 a while back. > > Yea, there is a pretty strong move toward range adaptors. If possible, I'm going to work on contributing a basic selection of them to LLVM's ADT specifically to address the immediate needs of range-based for loops.There’s a decent selection of range adaptors in Boost.Range [1]. I’m not sure the license [2] allows copying the source (IANAL), but any reason not use the same names? I don’t see any reason to reinvent the wheel here. [1]: http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/adaptors/reference.html [2]: http://www.boost.org/users/license.html
Chandler Carruth
2014-Mar-05 04:23 UTC
[LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
On Tue, Mar 4, 2014 at 8:07 PM, Duncan P. N. Exon Smith < dexonsmith at apple.com> wrote:> There’s a decent selection of range adaptors in Boost.Range [1]. I’m not > sure the license [2] allows copying the source (IANAL), but any reason not > use the same names? I don’t see any reason to reinvent the wheel here.Because I think that algorithms (and functions more generally) should be verbs. The names will be very similar all the same. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140304/035f54af/attachment.html>
Duncan P. N. Exon Smith
2014-Mar-05 05:26 UTC
[LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
On 2014 Mar 4, at 20:23, Chandler Carruth <chandlerc at google.com> wrote:> On Tue, Mar 4, 2014 at 8:07 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote: > There’s a decent selection of range adaptors in Boost.Range [1]. I’m not sure the license [2] allows copying the source (IANAL), but any reason not use the same names? I don’t see any reason to reinvent the wheel here. > > Because I think that algorithms (and functions more generally) should be verbs. The names will be very similar all the same.I agree. Algorithms should be verbs. However, I disagree that range adaptors are algorithms. “reverse” sounds like an algorithm. Consider, from the STL: template <class Iterator> void reverse(Iterator F, Iterator L); I’d expect a range version of the algorithm to look like this: template <class Range> void reverse(Range &R) { reverse(std::begin(R), std::end(R)); } On the other hand, “reversed” sounds like an accessor, and I’d expect it to look something like this: template <class Range> reversed_range<Range::iterator> reversed(Range &R) { return make_range(make_reverse_iterator(std::end(R)), make_reverse_iterator(std::begin(R))); } template <class Range> reversed_range<Range::const_iterator> reversed(const Range &R) { return make_range(make_reverse_iterator(std::end(R)), make_reverse_iterator(std::begin(R))); } template <class Iterator> iterator_range<Iterator> reversed(const reversed_range<Iterator> &R) { return make_range(R.end().base(), R.begin().base()); } IMO, Adaptors are more akin to accessors than they are to algorithms. If it has to be a verb, then I think getReversed() is better than reverse().
Maybe Matching Threads
- [LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
- [LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
- [LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
- [LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)
- [LLVMdev] [cfe-dev] C++11 reverse iterators (was C++11 is here)