Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/aal/algorithm.hpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#pragma once
#include <tuple>
#include <utility>

namespace aal {
namespace var {

template <typename I, typename... Is, typename P>
[[nodiscard]] constexpr auto
find(P const pred, I f, I const l, Is... fs) {
while (f != l) {
find(P pred, I f, I const l, Is... fs)
{
for (;f != l;++f, ((void)++fs, ...)) {
if (pred(*f, *fs...)) break;
++f, (++fs, ...);
}
return std::tuple{f, fs...};
}

template <typename I, typename... Is, typename P>
[[nodiscard]] constexpr auto
any_of(P const pred, I f, I const l, Is... fs) {
auto const t = find(pred, f, l, fs...);
any_of(P&& pred, I&& f, I const l, Is&&... fs) {
auto const t = find(std::forward<P>(pred), std::forward<I>(f), l,
std::forward<Is>(fs)...);
return std::get<0>(t) != l;
}

template <typename I, typename... Is, typename O, typename Op>
constexpr auto
transform(Op const op, O o, I f, I const l, Is... fs) {
while (f != l) {
transform(Op op, O o, I f, I const l, Is... fs) {
for (;f != l;++o, (void)++f, ((void)++fs, ...)) {
*o = op(*f, *fs...);
++o, ++f, (++fs, ...);
}
return o;
}
Expand Down