non-static function call in Operation + utils in anonymous range

This commit is contained in:
Christian Zimmermann 2018-04-28 17:33:57 +02:00
parent 1c7a21a8b8
commit 714eecd663
4 changed files with 58 additions and 8 deletions

View file

@ -248,6 +248,7 @@ namespace MultiArrayTools
typedef decltype(PackNum<sizeof...(Ops)-1>::template mkSteps<Ops...>(0, mOps)) ETuple;
Operation(const Ops&... ops);
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
template <class ET>
inline T get(ET pos) const;
@ -522,7 +523,19 @@ namespace MultiArrayTools
template <typename T, class OpFunction, class... Ops>
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
mOps(ops...) {}
mOps(ops...)
{
static_assert( FISSTATIC, "need function instance for non-static function" );
}
template <typename T, class OpFunction, class... Ops>
Operation<T,OpFunction,Ops...>::Operation(std::shared_ptr<OpFunction> ff,
const Ops&... ops) :
mOps(ops...),
mF(ff)
{
static_assert( not FISSTATIC, "using instance of function supposed to be static" );
}
template <typename T, class OpFunction, class... Ops>
template <class ET>
@ -530,7 +543,7 @@ namespace MultiArrayTools
{
typedef std::tuple<Ops...> OpTuple;
return PackNum<sizeof...(Ops)-1>::
template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(pos, mOps);
template mkOpExpr<SIZE,T,ET,OpTuple,OpFunction>(mF, pos, mOps);
}
template <typename T, class OpFunction, class... Ops>

View file

@ -13,6 +13,26 @@
namespace MultiArrayHelper
{
template <bool ISSTATIC>
struct Application
{
template <class OpFunction, typename T, typename... Ts>
static inline T apply(std::shared_ptr<OpFunction> f, T a, Ts... as)
{
return (*f)(a, as...);
}
};
template <>
struct Application<true>
{
template <class OpFunction, typename T, typename... Ts>
static inline T apply(std::shared_ptr<OpFunction> f, T a, Ts... as)
{
return OpFunction::apply(a, as...);
}
};
template <size_t N>
struct PackNum
@ -41,13 +61,13 @@ namespace MultiArrayHelper
}
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
static inline T mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args)
{
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
return PackNum<N-1>::template mkOpExpr<NEXT,T,ETuple,OpTuple,OpFunction,T,Args...>
( pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
( f, pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
}
template <class OpTuple, class Expr>
@ -94,14 +114,15 @@ namespace MultiArrayHelper
{
std::get<0>(out) = second.rootSteps( std::get<0>(siar) );
}
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
static inline T mkOpExpr(const ETuple& pos, const OpTuple& ops, const Args&... args)
static inline T mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args)
{
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
static_assert(NEXT == 0, "inconsistent array positions");
return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
return Application<OpFunction::FISSTATIC>::apply(f, std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
//return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
}
template <class OpTuple, class Expr>

View file

@ -51,7 +51,12 @@ namespace MultiArrayTools
virtual IndexType begin() const override;
virtual IndexType end() const override;
std::shared_ptr<RangeBase> sub(size_t num) const;
template <class Range>
std::shared_ptr<Range> fullsub(size_t num) const;
friend AnonymousRangeFactory;
protected:
@ -118,6 +123,12 @@ namespace MultiArrayTools
//RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
}
template <class Range>
std::shared_ptr<Range> AnonymousRange::fullsub(size_t num) const
{
return std::dynamic_pointer_cast<Range>( mOrig.at(num) );
}
/*****************
* Functions *
*****************/

View file

@ -54,6 +54,11 @@ namespace MultiArrayTools
i = size();
return i;
}
std::shared_ptr<RangeBase> AnonymousRange::sub(size_t num) const
{
return mOrig.at(num);
}
/*****************
* Functions *