86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
|
#ifndef ALSK_ALSK_EDSL_OP_IMPL_FARM_H
|
||
|
#define ALSK_ALSK_EDSL_OP_IMPL_FARM_H
|
||
|
|
||
|
#include <utility>
|
||
|
|
||
|
#include "../traits.h"
|
||
|
#include "../../../skeleton/bone/farm.h"
|
||
|
#include "../../../skeleton/struct/struct.h"
|
||
|
#include "../../../skeleton/link/link.h"
|
||
|
|
||
|
namespace alsk {
|
||
|
namespace edsl {
|
||
|
|
||
|
template<typename, typename, typename> struct FarmSel;
|
||
|
|
||
|
template<typename Signature_, typename Task>
|
||
|
struct Farm: OperandBase {
|
||
|
Task task;
|
||
|
unsigned int n;
|
||
|
|
||
|
constexpr Farm(Task task, unsigned int n)
|
||
|
noexcept(noexcept(Task{std::move(task)})):
|
||
|
task{std::move(task)}, n{n} {}
|
||
|
|
||
|
template<typename S>
|
||
|
constexpr Farm(Farm<S, Task> const& o)
|
||
|
noexcept(noexcept(Task{o.task})):
|
||
|
task{o.task}, n{o.n} {}
|
||
|
|
||
|
template<typename S>
|
||
|
constexpr Farm(Farm<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::Farm, typename Task::Struct>;
|
||
|
using Links = L<alsk::Farm, 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 Farm<Signature, Task>{std::move(*this)};
|
||
|
}
|
||
|
|
||
|
template<typename Signature>
|
||
|
constexpr auto link() const& {
|
||
|
return Farm<Signature, Task>{*this};
|
||
|
}
|
||
|
|
||
|
template<typename Rhs, std::enable_if_t<isOperand<Rhs>>* = nullptr>
|
||
|
constexpr auto select(Rhs const& rhs) {
|
||
|
return FarmSel<GetReturnType<Rhs>(), Task, Rhs>{task, rhs, n};
|
||
|
}
|
||
|
};
|
||
|
|
||
|
template<typename Signature = void(), typename Task, std::enable_if_t<isOperand<Task>>* = nullptr>
|
||
|
constexpr auto farm(Task const& task, unsigned int n = 0) {
|
||
|
return Farm<Signature, Task>{task, n};
|
||
|
}
|
||
|
|
||
|
template<typename Rhs, std::enable_if_t<isOperand<Rhs>>* = nullptr>
|
||
|
constexpr auto operator*(Rhs const& rhs) {
|
||
|
return Farm<void(), Rhs>{rhs, 0};
|
||
|
}
|
||
|
|
||
|
template<typename Rhs, std::enable_if_t<isOperand<Rhs>>* = nullptr>
|
||
|
constexpr auto operator*(unsigned int n, Rhs const& rhs) {
|
||
|
return Farm<void(), Rhs>{rhs, n};
|
||
|
}
|
||
|
|
||
|
template<typename Lhs, std::enable_if_t<isOperand<Lhs>>* = nullptr>
|
||
|
constexpr auto operator*(Lhs const& lhs, unsigned int n) {
|
||
|
return Farm<void(), Lhs>{lhs, n};
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|