diff --git a/src/core/container_func.hpp b/src/core/container_func.hpp index b0128229c0..6b459cdd08 100644 --- a/src/core/container_func.hpp +++ b/src/core/container_func.hpp @@ -46,4 +46,19 @@ int find_index(Container const &container, typename Container::const_reference i return -1; } +/** + * Move elements between first and last to a new position, rotating elements in between as necessary. + * @param first Iterator to first element to move. + * @param last Iterator to (end-of) last element to move. + * @param position Iterator to where range should be moved to. + * @returns Iterators to first and last after being moved. + */ +template +auto Slide(TIter first, TIter last, TIter position) -> std::pair +{ + if (last < position) return { std::rotate(first, last, position), position }; + if (position < first) return { position, std::rotate(position, first, last) }; + return { first, last }; +} + #endif /* CONTAINER_FUNC_HPP */