13template <
typename Iterator>
15 while ((first != last) && (first != --last)) {
16 swap(*first++, *last);
20template <
typename Iterator>
26 Iterator max_iter = first;
29 while (first != last) {
30 if (*max_iter < *first) {
39template <
typename Iterator,
typename Compare>
45 Iterator max_iter = first;
48 while (first != last) {
49 if (comp(*max_iter, *first)) {
58template <
typename Iterator>
64 Iterator min_iter = first;
67 while (first != last) {
68 if (*first < *min_iter) {
77template <
typename Iterator,
typename Compare>
83 Iterator min_iter = first;
86 while (first != last) {
87 if (comp(*first, *min_iter)) {
98template <
typename Iterator1,
typename Iterator2>
100 while (first1 != last1) {
101 if (*first1 != *first2) {
110template <
typename Iterator1,
typename Iterator2,
typename BinaryPredicate>
111bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate pred)
FL_NO_EXCEPT {
112 while (first1 != last1) {
113 if (!pred(*first1, *first2)) {
122template <
typename Iterator1,
typename Iterator2>
124 while (first1 != last1 && first2 != last2) {
125 if (*first1 != *first2) {
131 return first1 == last1 && first2 == last2;
134template <
typename Iterator1,
typename Iterator2,
typename BinaryPredicate>
135bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, BinaryPredicate pred)
FL_NO_EXCEPT {
136 while (first1 != last1 && first2 != last2) {
137 if (!pred(*first1, *first2)) {
143 return first1 == last1 && first2 == last2;
148template <
typename Iterator1,
typename Iterator2>
150 while (first1 != last1 && first2 != last2) {
151 if (*first1 < *first2) {
154 if (*first2 < *first1) {
163 return (first1 == last1) && (first2 != last2);
167template <
typename Iterator1,
typename Iterator2,
typename Compare>
169 while (first1 != last1 && first2 != last2) {
170 if (comp(*first1, *first2)) {
173 if (comp(*first2, *first1)) {
182 return (first1 == last1) && (first2 != last2);
185template <
typename Container1,
typename Container2>
187 fl::size size1 = c1.size();
188 fl::size size2 = c2.size();
189 if (size1 != size2) {
192 return equal(c1.begin(), c1.end(), c2.begin(), c2.end());
195template <
typename Container1,
typename Container2,
typename BinaryPredicate>
197 fl::size size1 = c1.size();
198 fl::size size2 = c2.size();
199 if (size1 != size2) {
202 return equal(c1.begin(), c1.end(), c2.begin(), c2.end(), pred);
206template <
typename Iterator,
typename T>
208 while (first != last) {
214template <
typename Iterator,
typename T>
216 while (first != last) {
217 if (*first ==
value) {
225template <
typename Iterator,
typename UnaryPredicate>
227 while (first != last) {
236template <
typename Iterator,
typename UnaryPredicate>
238 while (first != last) {
247template <
typename Iterator,
typename T>
249 while (first != last) {
250 if (*first == old_value) {
257template <
typename Iterator,
typename UnaryPredicate,
typename T>
259 while (first != last) {
267template <
typename Iterator,
typename T>
270 while (first != last) {
271 if (!(*first ==
value)) {
282template <
typename Iterator,
typename UnaryPredicate>
285 while (first != last) {
302template <
typename Iterator,
typename Compare>
304 if (first == last)
return;
306 for (Iterator i = first + 1; i != last; ++i) {
310 while (j != first && comp(
value, *(j - 1))) {
320template <
typename Iterator,
typename Compare>
322 if (comp(*middle, *first)) {
323 if (comp(*last, *middle)) {
325 }
else if (comp(*last, *first)) {
331 if (comp(*last, *first)) {
333 }
else if (comp(*last, *middle)) {
342template <
typename Iterator,
typename Compare>
344 Iterator middle = first + (last - first) / 2;
348 swap(*pivot_iter, *(last - 1));
349 Iterator pivot = last - 1;
352 for (Iterator j = first; j != pivot; ++j) {
353 if (comp(*j, *pivot)) {
364template <
typename Iterator,
typename Compare>
366 Iterator root = start;
368 while (root - first <= (
end - first - 2) / 2) {
369 Iterator child = first + 2 * (root - first) + 1;
370 Iterator swap_iter = root;
372 if (comp(*swap_iter, *child)) {
376 if (child + 1 <=
end && comp(*swap_iter, *(child + 1))) {
377 swap_iter = child + 1;
380 if (swap_iter == root) {
383 swap(*root, *swap_iter);
389template <
typename Iterator,
typename Compare>
391 Iterator start = first + (last - first - 2) / 2;
395 if (start == first) {
402template <
typename Iterator,
typename Compare>
406 Iterator
end = last - 1;
407 while (
end > first) {
415template <
typename Iterator,
typename Compare>
417 if (last - first <= 16) {
422 Iterator pivot =
partition(first, last, comp);
428template <
typename Iterator>
430 if (first == middle || middle == last) {
434 Iterator next = middle;
435 while (first != next) {
436 swap(*first++, *next++);
439 }
else if (first == middle) {
446template <
typename Iterator,
typename T,
typename Compare>
448 auto count = last - first;
450 auto step = count / 2;
451 Iterator it = first +
step;
452 if (comp(*it,
value)) {
463template <
typename Iterator,
typename Compare>
466 if (first == middle || middle == last) {
471 auto left_size = middle - first;
472 auto right_size = last - middle;
473 if (left_size + right_size <= 32) {
475 Iterator left = first;
476 Iterator right = middle;
478 while (left < middle && right < last) {
479 if (!comp(*right, *left)) {
485 Iterator shift_end = right;
486 Iterator shift_start = left;
489 while (shift_end > shift_start) {
490 *shift_end =
fl::move(*(shift_end - 1));
504 if (left_size == 0 || right_size == 0) {
508 if (left_size == 1) {
515 if (right_size == 1) {
523 Iterator left_mid = first + left_size / 2;
530 Iterator new_middle = left_mid + (right_mid - middle);
538template <
typename Iterator,
typename Compare>
540 auto size = last - first;
546 Iterator middle = first + size / 2;
554namespace adl_barrier {
557template <
typename Iterator,
typename T,
typename Compare>
562template <
typename Iterator,
typename T>
566 [](
const value_type& a,
const T& b) {
return a < b; });
570template <
typename Iterator,
typename Compare>
572 if (first == last || first + 1 == last) {
580template <
typename Iterator>
584 sort(first, last, [](
const value_type& a,
const value_type& b) {
return a < b; });
588template <
typename Iterator,
typename Compare>
590 if (first == last || first + 1 == last) {
598template <
typename Iterator>
602 stable_sort(first, last, [](
const value_type& a,
const value_type& b) {
return a < b; });
618template <
typename Iterator,
typename Compare>
620 if (first == last || first + 1 == last) {
626template <
typename Iterator>
630 [](
const value_type& a,
const value_type& b) {
return a < b; });
634template <
typename Iterator,
typename RandomGenerator>
640 auto n = last - first;
641 for (
auto i = n - 1; i > 0; --i) {
643 auto j =
g() % (i + 1);
646 swap(*(first + i), *(first + j));
651template <
typename Iterator>
657 auto n = last - first;
658 for (
auto i = n - 1; i > 0; --i) {
660 auto j = rng(
static_cast<u32
>(i + 1));
663 swap(*(first + i), *(first + j));
668template <
typename Iterator>
Keeps fl's generic templates out of argument-dependent lookup (ADL).
A random number generator class that wraps FastLED's random functions.
void replace(Iterator first, Iterator last, const T &old_value, const T &new_value) FL_NO_EXCEPT
constexpr T * end(T(&array)[N]) FL_NO_EXCEPT
Iterator remove_if(Iterator first, Iterator last, UnaryPredicate pred) FL_NO_EXCEPT
Iterator max_element(Iterator first, Iterator last) FL_NO_EXCEPT
Iterator lower_bound(Iterator first, Iterator last, const T &value, Compare comp) FL_NO_EXCEPT
bool equal_container(const Container1 &c1, const Container2 &c2) FL_NO_EXCEPT
Iterator find_if_not(Iterator first, Iterator last, UnaryPredicate pred) FL_NO_EXCEPT
Iterator min_element(Iterator first, Iterator last) FL_NO_EXCEPT
void sort_small(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
Iterator find_if(Iterator first, Iterator last, UnaryPredicate pred) FL_NO_EXCEPT
void replace_if(Iterator first, Iterator last, UnaryPredicate pred, const T &new_value) FL_NO_EXCEPT
bool lexicographical_compare(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) FL_NO_EXCEPT
void sort(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void fill(Iterator first, Iterator last, const T &value) FL_NO_EXCEPT
void stable_sort(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
Iterator remove(Iterator first, Iterator last, const T &value) FL_NO_EXCEPT
bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2) FL_NO_EXCEPT
void reverse(Iterator first, Iterator last) FL_NO_EXCEPT
Iterator find(Iterator first, Iterator last, const T &value) FL_NO_EXCEPT
void shuffle(Iterator first, Iterator last, RandomGenerator &g) FL_NO_EXCEPT
Iterator partition(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void mergesort_impl(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void rotate_impl(Iterator first, Iterator middle, Iterator last) FL_NO_EXCEPT
Iterator lower_bound_impl(Iterator first, Iterator last, const T &value, Compare comp) FL_NO_EXCEPT
void quicksort_impl(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void heapify(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void sift_down(Iterator first, Iterator start, Iterator end, Compare comp) FL_NO_EXCEPT
Iterator median_of_three(Iterator first, Iterator middle, Iterator last, Compare comp) FL_NO_EXCEPT
void heap_sort(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void insertion_sort(Iterator first, Iterator last, Compare comp) FL_NO_EXCEPT
void merge_inplace(Iterator first, Iterator middle, Iterator last, Compare comp) FL_NO_EXCEPT
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
void swap(array< T, N > &lhs, array< T, N > &rhs) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
constexpr int type_rank< T >::value
math::random & default_random() FL_NO_EXCEPT
Global default random number generator instance.
expected< T, E > result
Alias for expected (Rust-style naming)
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NO_EXCEPT
Base definition for an LED controller.