6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_ROTATE_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_ROTATE_HPP_
13#include "arene/base/algorithm/detail/traits.hpp"
26#include "arene/base/stdlib_choice/declval.hpp"
27#include "arene/base/stdlib_choice/enable_if.hpp"
28#include "arene/base/stdlib_choice/ignore.hpp"
29#include "arene/base/stdlib_choice/is_copy_assignable.hpp"
30#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
31#include "arene/base/stdlib_choice/is_move_assignable.hpp"
32#include "arene/base/stdlib_choice/is_move_constructible.hpp"
33#include "arene/base/stdlib_choice/move.hpp"
48namespace algorithm_detail {
49namespace rotate_detail {
61 template <
class Iterator, constra
ints<std::enable_if_t<base::is_forward_iterator_v<Iterator>>> =
nullptr>
62 static constexpr auto rotate_left(Iterator first, Iterator last) -> Iterator {
76 template <
class Iterator, constra
ints<std::enable_if_t<base::is_forward_iterator_v<Iterator>>> =
nullptr>
77 static constexpr auto rotate_right(Iterator first, Iterator last) -> Iterator {
95 template <
class Iterator, constra
ints<std::enable_if_t<base::is_forward_iterator_v<Iterator>>> =
nullptr>
96 static constexpr auto rotate_forward(Iterator first, Iterator middle, Iterator last) -> Iterator {
97 Iterator iter{middle};
99 ::arene::base::iter_swap(first, iter);
100 arene::base::advance(first, 1);
101 arene::base::advance(iter, 1);
105 if (first == middle) {
109 Iterator
const result{first};
110 if (first != middle) {
113 ::arene::base::iter_swap(first, iter);
114 arene::base::advance(first, 1);
115 arene::base::advance(iter, 1);
117 if (first == middle) {
121 }
else if (first == middle) {
140 template <
typename Iterator, constra
ints<std::enable_if_t<base::is_random_access_iterator_v<Iterator>>> =
nullptr>
141 static constexpr auto rotate_random_access(Iterator first, Iterator middle, Iterator last)
145 if (distance_to_middle == distance_from_middle) {
149 auto const gcd_distance =
::arene::base::gcd(distance_to_middle, distance_from_middle);
151 while (pos != first) {
152 arene::base::advance(pos, -1);
161 if (distance_to_middle < distance_to_end) {
162 arene::base::advance(pos2, distance_to_middle);
166 }
while (pos2 != pos);
188 static constexpr auto impl(Iterator first, Iterator middle, Iterator last) -> Iterator {
190 return rotate_left(first, last);
192 return rotate_forward(first, middle, last);
211 static constexpr auto impl(Iterator first, Iterator middle, Iterator last) -> Iterator {
213 return rotate_left(first, last);
216 return rotate_right(first, last);
218 return rotate_forward(first, middle, last);
231 template <
class Iterator, constra
ints<std::enable_if_t<base::is_random_access_iterator_v<Iterator>>> =
nullptr>
232 static constexpr auto impl(Iterator first, Iterator middle, Iterator last) -> Iterator {
235 return rotate_left(first, last);
238 return rotate_right(first, last);
240 return rotate_random_access(first, middle, last);
272 constexpr auto operator()(Iterator first, Iterator middle, Iterator last)
const noexcept(
277 noexcept(arene::base::advance(
281 std::is_nothrow_move_constructible<remove_cvref_t<iter_reference_t<Iterator>>>::value &&
282 std::is_nothrow_move_assignable<remove_cvref_t<iter_reference_t<Iterator>>>::value &&
286 if (first == middle) {
289 if (middle == last) {
292 return impl(first, middle, last);
Provides a backport of C++17's constexpr std::advance.
#define ARENE_CPP14_INLINE_VARIABLE(type, name)
Emulates C++17's inline variable declarations for function objects.
Definition cpp14_inline.hpp:69
static constexpr value_type value
Definition integral_constant.hpp:34
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
constexpr bool is_random_access_iterator_v
Definition iterator_category_traits.hpp:332
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
constexpr auto distance(Iterator first, Iterator last) noexcept(noexcept(distance_impl::do_distance(first, last, typename std::iterator_traits< Iterator >::iterator_category{}))) -> typename std::iterator_traits< Iterator >::difference_type
Find the number of elements between first and last.
Definition distance.hpp:79
constexpr bool denotes_nothrow_iterable_range_v
Check if an iterator/sentinel pair form an iterable range that can be iterated without throwing.
constexpr auto swap_ranges(SourceIterator first1, SourceIterator last1, DestIterator first2) noexcept(noexcept(::arene::base::iter_swap(first1++, first2++)) &&noexcept(first1 !=last1)) -> DestIterator
Exchanges elements between range [first1, last1) and another range starting at first2....
Definition swap_ranges.hpp:39
constexpr bool is_nothrow_equality_comparable_v
constexpr auto gcd(Integral lhs, Integral rhs) noexcept -> Integral
Calculates the Greatest Common Divisor (GCD) of two Integral values.
Definition gcd.hpp:26
constexpr auto move_backward(InIterator first, InIterator last, OutIterator result) noexcept(//noexcept(--result) &&noexcept(*result) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) noexcept(*last) &&noexcept(--last) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) noexcept(first !=last) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) CODEQLFP(M5-14-1) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements from the range [first, last), to another range ending at result....
Definition move_backward.hpp:45
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
typename iter_difference_t_detail::iter_difference_t_impl< remove_cvref_t< Itr > >::type iter_difference_t
Computes the difference type of the given iterator type.
Definition iter_difference_t.hpp:87
ARENE_NODISCARD constexpr auto prev(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, -steps))) -> Iterator
Produces the Nth predecessor (or successor if steps is negative) of an iterator.
Definition prev.hpp:44
Definition accumulate.hpp:36
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
static constexpr auto const & ignore
An object to which anything can be assigned, which ignores the assigned value.
Definition ignore.hpp:72