rosa/inc/alsk/skeleton/bone/farmsel.h

61 lines
1.7 KiB
C
Raw Permalink Normal View History

2021-05-10 16:14:24 +00:00
#ifndef ALSK_ALSK_SKELETON_BONE_FARMSEL_H
#define ALSK_ALSK_SKELETON_BONE_FARMSEL_H
#include "../bonebase.h"
namespace alsk {
template<typename, typename, typename> struct FarmSel;
template<
typename Signature,
typename Task_, typename TaskLinks_,
typename Select_, typename SelectLinks_
>
struct FarmSel<Signature, tmp::Pack<Task_, TaskLinks_>, tmp::Pack<Select_, SelectLinks_>>: SkeletonBase {
using Task = Task_;
using Select = Select_;
using TaskLinks = TaskLinks_;
using SelectLinks = SelectLinks_;
using Links = tmp::Pack<TaskLinks, SelectLinks>;
using PackP = tmp::Parameters<Signature>;
using PackR = Returns<Links>;
using PackX = tmp::Pack<>;
using Packs = arg::Placeholders<PackP, PackR, PackX>;
Task task;
Select select;
std::size_t n;
};
template<>
struct SkeletonTraits<FarmSel> {
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 TraverserTask = SkeletonTraversal<typename std::decay_t<Skeleton>::Task>;
using TraverserSelect = SkeletonTraversal<typename std::decay_t<Skeleton>::Select>;
return function(parDepth, skeleton,
TraverserTask::execute(parDepth+1, skeleton.task, function, std::forward<T>(init)),
TraverserSelect::execute(parDepth, skeleton.select, 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(FarmSel<Args...> const& s, F f) {
f(s.task, s.n);
f(s.select, 1);
}
}
#endif