rosa/inc/alsk/skeleton/bone/farm.h
2021-05-10 18:14:24 +02:00

52 lines
1.3 KiB
C++

#ifndef ALSK_ALSK_SKELETON_BONE_FARM_H
#define ALSK_ALSK_SKELETON_BONE_FARM_H
#include "../bonebase.h"
namespace alsk {
template<typename, typename> struct Farm;
template<
typename Signature,
typename Task_, typename TaskLinks_
>
struct Farm<Signature, tmp::Pack<Task_, TaskLinks_>>: SkeletonBase {
using Task = Task_;
using TaskLinks = TaskLinks_;
using Links = tmp::Pack<TaskLinks>;
using PackP = tmp::Parameters<Signature>;
using PackR = Returns<Links>;
using PackX = tmp::Pack<>;
using Packs = arg::Placeholders<PackP, PackR, PackX>;
Task task;
std::size_t n;
};
template<>
struct SkeletonTraits<Farm> {
static constexpr bool serial = false;
template<typename Skeleton, typename F, typename T>
static constexpr decltype(auto) traverse(std::size_t parDepth, Skeleton&& skeleton, F&& function, T&& init) {
using Traverser = SkeletonTraversal<typename std::decay_t<Skeleton>::Task>;
return function(parDepth, skeleton, Traverser::execute(parDepth+1, skeleton.task, function, std::forward<T>(init)));
}
template<typename Skeleton>
static constexpr std::size_t parallelizability(Skeleton&& skeleton) noexcept {
return std::forward<Skeleton>(skeleton).n;
}
};
template<typename... Args, typename F>
void skeletonTraversal(Farm<Args...> const& s, F&& f) {
std::forward<F>(f)(s.task, s.n);
}
}
#endif