non-static function call in Operation + utils in anonymous range
This commit is contained in:
parent
1c7a21a8b8
commit
714eecd663
4 changed files with 58 additions and 8 deletions
|
@ -248,6 +248,7 @@ namespace MultiArrayTools
|
||||||
typedef decltype(PackNum<sizeof...(Ops)-1>::template mkSteps<Ops...>(0, mOps)) ETuple;
|
typedef decltype(PackNum<sizeof...(Ops)-1>::template mkSteps<Ops...>(0, mOps)) ETuple;
|
||||||
|
|
||||||
Operation(const Ops&... ops);
|
Operation(const Ops&... ops);
|
||||||
|
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
||||||
|
|
||||||
template <class ET>
|
template <class ET>
|
||||||
inline T get(ET pos) const;
|
inline T get(ET pos) const;
|
||||||
|
@ -522,7 +523,19 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
Operation<T,OpFunction,Ops...>::Operation(const Ops&... 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 <typename T, class OpFunction, class... Ops>
|
||||||
template <class ET>
|
template <class ET>
|
||||||
|
@ -530,7 +543,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
typedef std::tuple<Ops...> OpTuple;
|
typedef std::tuple<Ops...> OpTuple;
|
||||||
return PackNum<sizeof...(Ops)-1>::
|
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>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
|
|
|
@ -13,6 +13,26 @@
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
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>
|
template <size_t N>
|
||||||
struct PackNum
|
struct PackNum
|
||||||
|
@ -41,13 +61,13 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
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;
|
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
|
||||||
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
|
static_assert(LAST > NextOpType::SIZE, "inconsistent array positions");
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
||||||
return PackNum<N-1>::template mkOpExpr<NEXT,T,ETuple,OpTuple,OpFunction,T,Args...>
|
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>
|
template <class OpTuple, class Expr>
|
||||||
|
@ -96,12 +116,13 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t LAST, typename T, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
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;
|
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
||||||
static_assert(NEXT == 0, "inconsistent array positions");
|
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>
|
template <class OpTuple, class Expr>
|
||||||
|
|
|
@ -52,6 +52,11 @@ namespace MultiArrayTools
|
||||||
virtual IndexType begin() const override;
|
virtual IndexType begin() const override;
|
||||||
virtual IndexType end() 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;
|
friend AnonymousRangeFactory;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -118,6 +123,12 @@ namespace MultiArrayTools
|
||||||
//RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
//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 *
|
* Functions *
|
||||||
*****************/
|
*****************/
|
||||||
|
|
|
@ -55,6 +55,11 @@ namespace MultiArrayTools
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<RangeBase> AnonymousRange::sub(size_t num) const
|
||||||
|
{
|
||||||
|
return mOrig.at(num);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
* Functions *
|
* Functions *
|
||||||
*****************/
|
*****************/
|
||||||
|
|
Loading…
Reference in a new issue