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

52 lines
1.3 KiB
C
Raw Permalink Normal View History

2021-05-10 16:14:24 +00:00
#ifndef ALSK_ALSK_SKELETON_BONE_LOOP_H
#define ALSK_ALSK_SKELETON_BONE_LOOP_H
#include "../bonebase.h"
namespace alsk {
template<typename, typename> struct Loop;
template<
typename Signature,
typename Task_, typename TaskLinks_
>
struct Loop<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 = void;
using Packs = arg::Placeholders<PackP, PackR, PackX>;
Task task;
std::size_t n;
};
template<>
struct SkeletonTraits<Loop> {
static constexpr bool serial = true;
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, skeleton.task, function, std::forward<T>(init)));
}
template<typename Skeleton>
static constexpr std::size_t parallelizability(Skeleton&&) noexcept {
return 1;
}
};
template<typename... Args, typename F>
void skeletonTraversal(Loop<Args...> const& s, F&& f) {
std::forward<F>(f)(s.task, 1);
}
}
#endif