My omnium-gatherom of scripts and source code.
1#pragma once
2#include "prelude.hpp"
3#include <iostream>
4#include <functional>
5
6template <std::bidirectional_iterator I, std::sentinel_for<I> S,
7 class Proj = std::identity,
8 std::indirect_unary_predicate<std::projected<I, Proj>> Pred>
9 requires std::permutable<I>
10constexpr
11func gather(I f, S l, I p, Pred s, Proj proj = {}) -> ra::subrange<I>
12{
13 auto not1 = [](auto&& pred){
14 return [pred](auto const& x) { return not pred(x); };
15 };
16
17 auto r1 = ra::stable_partition(f, p, not1(s), proj);
18 auto r2 = ra::stable_partition(p, l, s, proj);
19 return { r1.begin(), r2.end() };
20}
21
22template <std::permutable I, std::sentinel_for<I> S>
23constexpr
24func slide(I f, S l, I p) -> ra::subrange<I>
25{
26 if (p > l) return ra::rotate(f, l, p);
27 if (p < f) return ra::rotate(p, f, l);
28 return { f, l };
29}
30
31template <std::permutable I, std::sentinel_for<I> S>
32[[nodiscard]] constexpr
33func intercalate(I f1, S l1, I f2, S l2) -> std::vector<typename std::iterator_traits<I>::value_type>
34{
35 using T = typename std::iterator_traits<I>::value_type;
36 auto make_pair = [](T x, T y) { return std::make_pair(x, y); };
37 auto concat = [](std::vector<T> vec, std::pair<T, T> e) { vec.push_back(e.first), vec.push_back(e.second); return vec; };
38
39 std::vector<T> out;
40 auto const s1 = std::distance(f1, l1);
41 auto const s2 = std::distance(f2, l2);
42
43 if (s1 > s2) return std::inner_product(f1, f1 + s2, f2, out, concat, make_pair);
44 return std::inner_product(f1, l1, f2, out, concat, make_pair);
45}
46
47template <std::permutable I, std::sentinel_for<I> S>
48func minimum_subsequence(I f, S l, )
49
50void print(auto const& x, std::string sep)
51{
52 std::cout << x << sep;
53}
54
55void print_range(auto const& r)
56{
57 for (let& e : r) print(e, " ");
58}