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);
52template<
typename T,
typename F>
53inline void erase_if(T &v, F predicate)
64template<
typename It,
typename UnaryPredicate>
65constexpr It rfind_if(It
const first, It
const last, UnaryPredicate predicate)
77template<
typename It,
typename UnaryPredicate>
78constexpr It rfind_if_not(It
const first, It
const last, UnaryPredicate predicate)
80 return rfind_if(first, last, [&](
hilet &x) {
85template<
typename It,
typename T>
86constexpr It rfind(It
const first, It
const last, T
const &value)
88 return rfind_if(first, last, [&](
hilet &x) {
100template<
typename It,
typename ItAny>
101[[nodiscard]]
constexpr It find_any(It data_first, It data_last, ItAny value_first, ItAny value_last)
noexcept
103 return std::find_if(data_first, data_last, [value_first, value_last](
hilet &data) {
105 return data == value;
116template<
typename ConstIt,
typename It,
typename UnaryPredicate>
117constexpr It find_cluster(ConstIt last, It start, UnaryPredicate predicate)
119 hilet cluster_id = predicate(*start);
121 for (
auto i = start + 1; i != last; ++i) {
122 if (predicate(*i) != cluster_id) {
135template<
typename ConstIt,
typename It,
typename UnaryPredicate>
136constexpr It rfind_cluster(ConstIt first, It start, UnaryPredicate predicate)
138 hilet cluster_id = predicate(*start);
140 if (start == first) {
146 if (predicate(*i) != cluster_id) {
165template<
typename ConstIt,
typename It,
typename UnaryPredicate>
166constexpr std::pair<It, It> bifind_cluster(ConstIt first, ConstIt last, It start, UnaryPredicate predicate)
168 return {rfind_cluster(first, start, predicate), find_cluster(last, start, predicate)};
176template<
typename It,
typename S,
typename F>
177inline void for_each_cluster(It first, It last, S IsClusterSeperator, F Function)
184 if (IsClusterSeperator(*first)) {
188 for (
auto i = first; i != last;) {
192 auto skipOverSeperator = (j == last) ? 0 : 1;
193 i = j + skipOverSeperator;
197template<
typename InputIt1,
typename InputIt2,
typename BinaryPredicate>
199rmismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate predicate)
noexcept
205 if (i1 == first1 && i2 == first2) {
206 return {last1, last2};
207 }
else if (i1 == first1) {
208 return {last1, --i2};
209 }
else if (i2 == first2) {
210 return {--i1, last2};
213 if (!predicate(*(--i1), *(--i2))) {
219template<
typename InputIt1,
typename InputIt2>
222 return rmismatch(first1, last1, first2, last2, [&](
auto a,
auto b) {
228T smoothstep(T x)
noexcept
230 x = std::clamp(x, T{0.0}, T{1.0});
231 return x * x * (3 - 2 * x);
235T inverse_smoothstep(T x)
255auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last,
auto index_op)
noexcept
263 src_indices.push_back(i);
267 for (
auto it = indices_first; it != indices_last; ++it, ++dst) {
268 hilet index = index_op(*it);
269 hi_axiom(index < size(src_indices));
271 auto src = [&src_indices, index]() {
274 src = src_indices[src];
275 }
while (src_indices[src] != index);
301auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last)
noexcept
303 return shuffle_by_index(first, last, indices_first, indices_last, [](
hilet &x) {
304 return narrow_cast<std::size_t>(x);
316template<
typename DataIt,
typename ValueIt>
317DataIt front_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last)
noexcept
319 for (
auto it = data_first; it != data_last; ++it) {
320 if (
std::find(value_first, value_last, *it) == value_last) {
337template<
typename DataIt,
typename ValueIt>
338DataIt back_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last)
noexcept
341 while (it != data_first) {
342 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
#define hi_unreachable()
Marker to tell the compiler that this line will never be executed.
Definition architecture.hpp:214
T back_inserter(T... args)