remove all PackNum stuff from multi_array_operation
This commit is contained in:
parent
44f6149a23
commit
acda91d792
3 changed files with 87 additions and 37 deletions
|
@ -983,52 +983,74 @@ namespace MultiArrayTools
|
|||
static_assert( not FISSTATIC, "using instance of static function" );
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <size_t I, size_t J, class ET>
|
||||
inline auto Operation<T,OpFunction,Ops...>::getSubX(ET pos) const
|
||||
template <size_t I, class OpFunction, class ETuple, class OpTuple, typename... Args>
|
||||
inline auto
|
||||
mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
|
||||
{
|
||||
// somehow get rid of the second condition (should NOT be needed if everything is correct)
|
||||
if constexpr(I == J or sizeof...(Ops)-1 == I){
|
||||
return std::get<J>(mOps.mOps).get(pos);
|
||||
}
|
||||
else {
|
||||
typedef typename std::remove_reference<decltype(std::get<I>(mOps.mOps))>::type
|
||||
NextOpType;
|
||||
return getSubX<I+1,J>(getX<NextOpType::SIZE>(pos));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <class ET>
|
||||
inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const
|
||||
{
|
||||
auto cre = [&](auto... args)
|
||||
{
|
||||
if constexpr(I == std::tuple_size<OpTuple>{}){
|
||||
if constexpr(OpFunction::FISSTATIC){
|
||||
return OpFunction::apply(args...);
|
||||
}
|
||||
else {
|
||||
return (*mF)(args...);
|
||||
(*f)(args...);
|
||||
}
|
||||
};
|
||||
return MA_CFOR2(i,0,sizeof...(Ops),i+1,return getSub<i>(pos);,cre);
|
||||
}
|
||||
else {
|
||||
typedef typename std::remove_reference<decltype(std::get<I>(ops))>::type NextOpType;
|
||||
return mkOpExpr<I+1>
|
||||
( f, getX<NextOpType::SIZE>(pos), ops, args..., std::get<I>(ops).get(pos));
|
||||
}
|
||||
}
|
||||
|
||||
template <size_t I, typename V, class OpFunction, class ETuple, class OpTuple, typename... Args>
|
||||
inline auto
|
||||
mkVOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
|
||||
{
|
||||
if constexpr(I == std::tuple_size<OpTuple>{}){
|
||||
if constexpr(OpFunction::FISSTATIC){
|
||||
return VFunc<OpFunction>::apply(args...);
|
||||
}
|
||||
else {
|
||||
auto vf = mkVFuncPtr(f);
|
||||
(*vf)(args...);
|
||||
}
|
||||
}
|
||||
else {
|
||||
typedef typename std::remove_reference<decltype(std::get<I>(ops))>::type NextOpType;
|
||||
return mkVOpExpr<I+1,V>( f, getX<NextOpType::SIZE>(pos), ops, args...,
|
||||
std::get<I>(ops).template vget<V>(pos));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <class ET>
|
||||
inline auto Operation<T,OpFunction,Ops...>::get(ET pos) const
|
||||
{
|
||||
return mkOpExpr<0>(mF, pos, mOps.mOps);
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <typename V, class ET>
|
||||
inline auto Operation<T,OpFunction,Ops...>::vget(ET pos) const
|
||||
{
|
||||
typedef std::tuple<Ops...> OpTuple;
|
||||
return PackNum<sizeof...(Ops)-1>::
|
||||
template mkVOpExpr<SIZE,V,ET,OpTuple,VFunc<OpFunction>>(mkVFuncPtr(mF), pos, mOps.mOps); // implement!!!
|
||||
return mkVOpExpr<0,V>(mF, pos, mOps.mOps);
|
||||
}
|
||||
|
||||
template <size_t I, class OpTuple, class ETuple>
|
||||
static inline void setOpPos(OpTuple& ot, const ETuple& et)
|
||||
{
|
||||
if constexpr(I != std::tuple_size<OpTuple>{}){
|
||||
typedef typename std::remove_reference<decltype(std::get<I>(ot))>::type NextOpType;
|
||||
std::get<I>( ot ).set( et );
|
||||
setOpPos<I+1>(ot, getX<NextOpType::SIZE>(et));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
template <class ET>
|
||||
inline Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::set(ET pos)
|
||||
{
|
||||
typedef std::tuple<Ops...> OpTuple;
|
||||
PackNum<sizeof...(Ops)-1>::template setOpPos<SIZE,OpTuple,ET>(mOps.mOps,pos);
|
||||
setOpPos<0>(mOps.mOps,pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -778,7 +778,43 @@ namespace MultiArrayTools
|
|||
|
||||
T const** data() const { assert(0); return nullptr; }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
template <typename T>
|
||||
struct TFold
|
||||
{
|
||||
TFold() = default;
|
||||
TFold(const TFold& in) = default;
|
||||
TFold& operator=(const TFold& in) = default;
|
||||
TFold(TFold&& in) = default;
|
||||
TFold& operator=(TFold&& in) = default;
|
||||
explicit TFold(const T v) : val(v) {}
|
||||
|
||||
T val;
|
||||
inline T& operator*() { return val; }
|
||||
inline const T& operator*() const { return val; }
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const TFold<T1>& a1, const TFold<T2>& a2)
|
||||
{
|
||||
return std::make_tuple(a1,a2);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2...>
|
||||
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const TFold<T1>& a1,
|
||||
const std::tuple<TFold<T2>...>& a2)
|
||||
{
|
||||
return std::tuple_cat(std::make_tuple(a1),a2);
|
||||
}
|
||||
|
||||
template <typename T2, typename T1...>
|
||||
inline std::tuple<TFold<T1>,TFold<T2>> operator,(const std::tuple<TFold<T1>...>& a1,
|
||||
const TFold<T2>& a2)
|
||||
{
|
||||
return std::tuple_cat(a1,std::make_tuple(a2));
|
||||
}
|
||||
*/
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
||||
{
|
||||
|
@ -804,12 +840,6 @@ namespace MultiArrayTools
|
|||
Operation(const Ops&... ops);
|
||||
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
||||
|
||||
template <size_t I, size_t J, class ET>
|
||||
inline auto getSubX(ET pos) const;
|
||||
|
||||
template <size_t J, class ET>
|
||||
inline auto getSub(ET pos) const { return getSubX<0,J>(pos); }
|
||||
|
||||
template <class ET>
|
||||
inline auto get(ET pos) const;
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ namespace MultiArrayTools
|
|||
return unpack<incr(idx),END,OFF>(incr, f, create, args..., tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -63,7 +62,6 @@ namespace MultiArrayTools
|
|||
#define MA_SCRFOR(i,beg,end,decr,expr,conc) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); })
|
||||
#define MA_SCRAFOR(i,beg,end,decr,expr,conc,arg) sfor<beg,end,-1>([&](auto i) constexpr { return decr; }, [&](auto i){ return expr; }, [&](auto f, auto next) { return f.conc(next); }, arg)
|
||||
#define MA_CFOR(i,beg,end,incr,expr,cre) unpack<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, [&](auto... args) { return cre(args...); })
|
||||
#define MA_CFOR2(i,beg,end,incr,expr,cre) unpack<beg,end,0>([&](auto i) constexpr { return incr; }, [&](auto i){ expr }, cre)
|
||||
|
||||
#define MA_SCFOR_X(i,beg,end,incr,expr,conc) sfor<beg,end,0>([](auto i) constexpr { return incr; }, [](auto i){ return expr; }, [](auto f, auto next) { return f.conc(next); })
|
||||
|
||||
|
|
Loading…
Reference in a new issue