add OperationPointer
This commit is contained in:
parent
49812b18e2
commit
23dddd3801
3 changed files with 86 additions and 1 deletions
|
@ -51,6 +51,10 @@ namespace MultiArrayTools
|
|||
template <typename T, class... Ranges>
|
||||
class ConstOperationRoot;
|
||||
|
||||
// multi_array_operation.h
|
||||
template <typename T, class Op>
|
||||
class OperationPointer;
|
||||
|
||||
// multi_array_operation.h
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation;
|
||||
|
|
|
@ -134,6 +134,14 @@ namespace MultiArrayTools
|
|||
return Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>(ll, THIS(), args...);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
auto OperationBase<T,OperationClass>::ptr() const
|
||||
-> OperationPointer<T,OperationClass>
|
||||
{
|
||||
return OperationPointer<T,OperationClass>(THIS());
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* AssignmentExpr *
|
||||
************************/
|
||||
|
@ -839,6 +847,40 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
|
||||
/**************************
|
||||
* OperationPointer *
|
||||
**************************/
|
||||
|
||||
template <typename T, class Op>
|
||||
template <class ET>
|
||||
inline const T* OperationPointer<T,Op>::get(ET pos) const
|
||||
{
|
||||
return &mOp.get(pos);
|
||||
}
|
||||
|
||||
template <typename T, class Op>
|
||||
template <class ET>
|
||||
inline OperationPointer<T,Op>& OperationPointer<T,Op>::set(ET pos)
|
||||
{
|
||||
mOp.set(pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, class Op>
|
||||
auto OperationPointer<T,Op>::rootSteps(std::intptr_t iPtrNum) const
|
||||
-> decltype(mOp.rootSteps(0))
|
||||
{
|
||||
return mOp.rootSteps(iPtrNum);
|
||||
}
|
||||
|
||||
template <typename T, class Op>
|
||||
template <class Expr>
|
||||
auto OperationPointer<T,Op>::loop(Expr exp) const
|
||||
-> decltype(mOp.loop(exp))
|
||||
{
|
||||
return mOp.loop(exp);
|
||||
}
|
||||
|
||||
/*******************
|
||||
* Operation *
|
||||
*******************/
|
||||
|
|
|
@ -82,7 +82,10 @@ namespace MultiArrayTools
|
|||
template <typename R, class... Args> // Args = Operation Classes
|
||||
auto a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;
|
||||
|
||||
|
||||
auto ptr() const
|
||||
-> OperationPointer<T,OperationClass>;
|
||||
|
||||
private:
|
||||
friend OperationClass;
|
||||
friend OperationTemplate<T,OperationClass>;
|
||||
|
@ -654,7 +657,43 @@ namespace MultiArrayTools
|
|||
T mVal;
|
||||
};
|
||||
|
||||
template <typename T, class Op>
|
||||
class OperationPointer : public OperationTemplate<const T*,OperationPointer<T,Op>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef OperationTemplate<const T*,OperationPointer<T,Op>> OT;
|
||||
|
||||
static constexpr size_t SIZE = Op::SIZE;
|
||||
static constexpr bool CONT = false;
|
||||
|
||||
private:
|
||||
Op mOp;
|
||||
|
||||
public:
|
||||
|
||||
OperationPointer(const Op& op) : mOp(op)
|
||||
{
|
||||
static_assert(Op::CONT,
|
||||
"OperationPointer can only be applied to containing operations");
|
||||
}
|
||||
|
||||
template <class ET>
|
||||
inline const T* get(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline OperationPointer& set(ET pos);
|
||||
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
|
||||
-> decltype(mOp.rootSteps(0));
|
||||
|
||||
template <class Expr>
|
||||
auto loop(Expr exp) const
|
||||
-> decltype(mOp.loop(exp));
|
||||
|
||||
T const** data() const { assert(0); return nullptr; }
|
||||
};
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
||||
|
|
Loading…
Reference in a new issue