15namespace hi::inline v1 {
22template<
typename T,
typename U,
typename F>
23inline T
transform(
const U &input, F operation)
26 result.reserve(input.size());
36template<
typename T, std::
size_t N,
typename F>
42 a.
at(i) = operation(i);
58constexpr It unordered_remove(It first, It last, It element)
60 hi_axiom(first != last);
64 auto new_last = last - 1;
65 swap(*element, *new_last);
69template<
typename It,
typename UnaryPredicate>
70constexpr It rfind_if(It
const first, It
const last, UnaryPredicate predicate)
82template<
typename It,
typename UnaryPredicate>
83constexpr It rfind_if_not(It
const first, It
const last, UnaryPredicate predicate)
85 return rfind_if(first, last, [&](
hilet &x) {
90template<
typename It,
typename T>
91constexpr It rfind(It
const first, It
const last, T
const &value)
93 return rfind_if(first, last, [&](
hilet &x) {
105template<
typename It,
typename ItAny>
106[[nodiscard]]
constexpr It find_any(It data_first, It data_last, ItAny value_first, ItAny value_last)
noexcept
108 return std::find_if(data_first, data_last, [value_first, value_last](
hilet &data) {
110 return data == value;
121template<
typename ConstIt,
typename It,
typename UnaryPredicate>
122constexpr It find_cluster(ConstIt last, It start, UnaryPredicate predicate)
124 hilet cluster_id = predicate(*start);
126 for (
auto i = start + 1; i != last; ++i) {
127 if (predicate(*i) != cluster_id) {
140template<
typename ConstIt,
typename It,
typename UnaryPredicate>
141constexpr It rfind_cluster(ConstIt first, It start, UnaryPredicate predicate)
143 hilet cluster_id = predicate(*start);
145 if (start == first) {
151 if (predicate(*i) != cluster_id) {
170template<
typename ConstIt,
typename It,
typename UnaryPredicate>
171constexpr std::pair<It, It> bifind_cluster(ConstIt first, ConstIt last, It start, UnaryPredicate predicate)
173 return {rfind_cluster(first, start, predicate), find_cluster(last, start, predicate)};
181template<
typename It,
typename S,
typename F>
182inline void for_each_cluster(It first, It last, S IsClusterSeperator, F Function)
189 if (IsClusterSeperator(*first)) {
193 for (
auto i = first; i != last;) {
197 auto skipOverSeperator = (j == last) ? 0 : 1;
198 i = j + skipOverSeperator;
202template<
typename InputIt1,
typename InputIt2,
typename BinaryPredicate>
204rmismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate predicate)
noexcept
210 if (i1 == first1 && i2 == first2) {
211 return {last1, last2};
212 }
else if (i1 == first1) {
213 return {last1, --i2};
214 }
else if (i2 == first2) {
215 return {--i1, last2};
218 if (!predicate(*(--i1), *(--i2))) {
224template<
typename InputIt1,
typename InputIt2>
227 return rmismatch(first1, last1, first2, last2, [&](
auto a,
auto b) {
233T smoothstep(T x)
noexcept
235 x = std::clamp(x, T{0.0}, T{1.0});
236 return x * x * (3 - 2 * x);
240T inverse_smoothstep(T x)
260auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last,
auto index_op)
noexcept
268 src_indices.push_back(i);
272 for (
auto it = indices_first; it != indices_last; ++it, ++dst) {
273 hilet index = index_op(*it);
274 hi_axiom(index < size(src_indices));
276 auto src = [&src_indices, index]() {
279 src = src_indices[src];
280 }
while (src_indices[src] != index);
306auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last)
noexcept
308 return shuffle_by_index(first, last, indices_first, indices_last, [](
hilet &x) {
309 return narrow_cast<std::size_t>(x);
321template<
typename DataIt,
typename ValueIt>
322DataIt front_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last)
noexcept
324 for (
auto it = data_first; it != data_last; ++it) {
325 if (
std::find(value_first, value_last, *it) == value_last) {
342template<
typename DataIt,
typename ValueIt>
343DataIt back_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last)
noexcept
346 while (it != data_first) {
347 if (
std::find(value_first, value_last, *(--it)) == value_last) {
This file includes required definitions.
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
T back_inserter(T... args)