[swift-evolution] Proposal: Implement a rotate algorithm, equivalent to std::rotate() in C++
dabrahams at apple.com
Mon Dec 14 02:51:26 CST 2015
> On Dec 13, 2015, at 2:20 AM, Sergey Bolshedvorsky via swift-evolution <swift-evolution at swift.org> wrote:
> Hi everyone,
> I’ve selected a ticket SR-125 as my first task (https://bugs.swift.org/browse/SR-125).
> I would like to propose an implementation of this method in Swift stdlib.
> std::rotate() method performs a left rotation on a range of elements.
> C++ declaration is void rotate (ForwardIterator first, ForwardIterator middle, ForwardIterator last)
> Specifically, it swaps the elements in the range [first, last) in such a way that the element middle becomes the first element of the new range and middle - 1 becomes the last element.
> A precondition of this function is that [first, n_first) and [middle, last) are valid ranges.
> What are your thoughts?
This is a really important algorithm, with applications even in GUI programming (see slide <http://www.bfilipek.com/2014/12/top-5-beautiful-c-std-algorithms.html#slide> and gather <http://www.bfilipek.com/2014/12/top-5-beautiful-c-std-algorithms.html#gather>), so I'm really happy someone is taking it on. You'll need different implementations depending on the index's protocol conformance <http://stackoverflow.com/questions/21160875/why-is-stdrotate-so-fast>. C++ implementations can get pretty sophisticated <http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?view=markup&pathrev=251836>. Would you like additional thoughts (and if so, of what nature), or will those do? ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution