rosa/inc/alsk/edsl/op/impl/loop.h
2021-05-10 18:14:24 +02:00

74 lines
1.6 KiB
C++

#ifndef ALSK_ALSK_EDSL_OP_IMPL_LOOP_H
#define ALSK_ALSK_EDSL_OP_IMPL_LOOP_H
#include <utility>
#include "../traits.h"
#include "../../../skeleton/bone/loop.h"
#include "../../../skeleton/struct/struct.h"
#include "../../../skeleton/link/link.h"
namespace alsk {
namespace edsl {
template<typename, typename> struct Farm;
template<typename Signature_, typename Task>
struct Loop: OperandBase {
Task task;
unsigned int n;
constexpr Loop(Task task, unsigned int n)
noexcept(noexcept(Task{std::move(task)})):
task{std::move(task)}, n{n}
{}
template<typename S>
constexpr Loop(Loop<S, Task> const& o)
noexcept(noexcept(Task{o.task})):
task{o.task}, n{o.n}
{}
template<typename S>
constexpr Loop(Loop<S, Task>&& o)
noexcept(noexcept(Task{std::move(o.task)})):
task{std::move(o.task)}, n{std::move(o.n)}
{}
using Signature = Signature_;
using Struct = S<alsk::Loop, typename Task::Struct>;
using Links = L<alsk::Loop, Signature, typename Task::Links>;
template<typename S>
constexpr void setup(S& skeleton) const {
skeleton.n = n;
setupFor(task, skeleton.task);
}
template<typename Signature>
constexpr auto link() const&& {
return Loop<Signature, Task>{std::move(*this)};
}
template<typename Signature>
constexpr auto link() const& {
return Loop<Signature, Task>{*this};
}
};
template<typename Signature = void(), typename Task>
constexpr auto loop(Task const& task, unsigned int n = 0) {
return Loop<Signature, Task>{task, n};
}
template<typename Signature, typename Task>
constexpr auto operator&(Farm<Signature, Task> const& farm) {
return Loop<Signature, Task>{farm.task, farm.n};
}
}
}
#endif