static cast function for operation classes + some fixes

This commit is contained in:
Christian Zimmermann 2018-08-06 12:46:12 +02:00
parent eb2bf52273
commit 86dc006b6f
3 changed files with 65 additions and 1 deletions

View file

@ -162,6 +162,40 @@ namespace MultiArrayTools
std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr;
};
template <typename T, class Op>
class StaticCast : public OperationTemplate<T,StaticCast<T,Op> >
{
private:
const Op& mOp;
public:
typedef T value_type;
typedef OperationBase<T,StaticCast<T,Op> > OT;
typedef typename Op::CRange CRange;
typedef typename Op::IndexType IndexType;
static constexpr size_t SIZE = Op::SIZE;
StaticCast(const Op& op);
template <class ET>
inline T get(ET pos) const;
auto rootSteps(std::intptr_t iPtrNum = 0) const
-> decltype(mOp.rootSteps(iPtrNum));
template <class Expr>
Expr loop(Expr exp) const;
};
template <typename T, class Op>
StaticCast<T,Op> staticcast(const Op& op)
{
return StaticCast<T,Op>(op);
}
template <class... Ranges>
class MetaOperationRoot : public OperationTemplate<std::tuple<typename Ranges::IndexType...>,
MetaOperationRoot<Ranges...> >
@ -548,6 +582,35 @@ namespace MultiArrayTools
return exp;
}
/********************
* StaticCast *
********************/
template <typename T, class Op>
StaticCast<T,Op>::StaticCast(const Op& op) : mOp(op) {}
template <typename T, class Op>
template <class ET>
inline T StaticCast<T,Op>::get(ET pos) const
{
return static_cast<T>( mOp.get(pos) );
}
template <typename T, class Op>
auto StaticCast<T,Op>::rootSteps(std::intptr_t iPtrNum) const
-> decltype(mOp.rootSteps(iPtrNum))
{
return mOp.rootSteps(iPtrNum);
}
template <typename T, class Op>
template <class Expr>
Expr StaticCast<T,Op>::loop(Expr exp) const
{
return mOp.loop(exp);
}
/****************************
* MetaOperationRoot *
****************************/

View file

@ -200,6 +200,7 @@ namespace MultiArrayTools
friend MultiRangeFactory<Ranges...>;
static constexpr bool HASMETACONT = false;
static constexpr bool defaultable = false;
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;

View file

@ -138,7 +138,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges>
ConstSlice<T,SRanges...>::ConstSlice(const MultiArray<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
MutableMultiArrayBase<T,SRanges...>
MultiArrayBase<T,SRanges...>
( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
mData( ma.data() )
{