+ForParam<P> ; does not compile...

This commit is contained in:
Christian Zimmermann 2018-01-18 23:14:49 +01:00
parent c1e1c85f7a
commit 5c96e47f69
3 changed files with 87 additions and 24 deletions

63
src/xfor/for_params.h Normal file
View file

@ -0,0 +1,63 @@
#ifndef __for_params_h__
#define __for_params_h__
namespace MultiArrayHelper
{
template <typename P>
class ForParam
{
private:
size_t mVal;
P mNext;
public:
ForParam(const ForParam& last, const ForParam& ext, size_t pos);
inline const P& next() const;
inline const size_t& val() const;
};
template <>
class ForParam<void>
{
private:
size_t mVal;
public:
ForParam(const ForParam& last, const ForParam& ext, size_t pos);
inline const size_t& val() const;
};
template <typename P>
ForParam<P>::ForParam(const ForParam& last, const ForParam& ext, size_t pos) :
mVal(last.val() + pos * ext.val()), mNext(last.next(), ext.next(), pos) {}
template <>
ForParam<void>::ForParam(const ForParam& last, const ForParam& ext, size_t pos) :
mVal(last.val() + pos * ext.val()) {}
template <typename P>
inline const P& ForParam<P>::next() const
{
return mNext;
}
template <typename P>
inline const size_t& ForParam<P>::val() const
{
return mVal;
}
template <>
inline const size_t& ForParam<void>::val() const
{
return mVal;
}
} // end namespace MultiArrayHelper
#endif

View file

@ -17,7 +17,7 @@ namespace MultiArrayHelper
struct XFPackNum
{
template <class ETuple, typename... Args>
static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args)
static inline ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args)
{
return std::move( XFPackNum<N-1>::mkPos(pos, et, lt, std::get<N>(lt) + pos * std::get<N>(et), args...) );
}
@ -27,7 +27,7 @@ namespace MultiArrayHelper
struct XFPackNum<0>
{
template <class ETuple, typename... Args>
static ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args)
static inline ETuple mkPos(size_t pos, const ETuple& et, const ETuple& lt, const Args&... args)
{
return ETuple(std::get<0>(lt) + pos * std::get<0>(et), args...);
}

View file

@ -7,6 +7,7 @@
#include <tuple>
#include "xfor/for_utils.h"
#include "xfor/for_type.h"
#include "xfor/for_params.h"
namespace MultiArrayHelper
{
@ -41,16 +42,18 @@ namespace MultiArrayHelper
//For& operator=(const For& in) = default;
const IndexClass* mIndPtr;
size_t mSPos;
size_t mMax;
Expr mExpr;
decltype(mExpr.rootSteps()) mExt;
typedef decltype(mExpr.rootSteps()) FParType;
FParType mExt;
public:
static size_t layer() { return Expr::layer() + 1; }
static const size_t LAYER = Expr::LAYER + 1;
static const size_t SIZE = std::remove_reference<Expr>::type::SIZE;
typedef decltype(mExpr.rootSteps()) ETuple;
For(For&& in) = default;
For& operator=(For&& in) = default;
@ -62,10 +65,10 @@ namespace MultiArrayHelper
Expr&& expr);
inline void operator()(size_t mlast, const ETuple& last) const;
inline void operator()(size_t mlast, const FParType& last) const;
inline void operator()(size_t mlast = 0) const;
ETuple rootSteps(std::intptr_t iPtrNum = 0) const;
FParType rootSteps(std::intptr_t iPtrNum = 0) const;
};
@ -90,7 +93,7 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr, ForType FT>
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
Expr&& expr) :
mIndPtr(indPtr.get()), mExpr(expr),
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr),
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() )))
{
assert(mIndPtr != nullptr);
@ -101,7 +104,8 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr, ForType FT>
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
Expr&& expr) :
mIndPtr(indPtr), mExpr(std::forward<Expr>( expr )),
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(std::forward<Expr>( expr )),
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ))
{
assert(mIndPtr != nullptr);
@ -111,15 +115,13 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr, ForType FT>
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
const ETuple& last) const
const FParType& last) const
{
auto& ind = *mIndPtr;
//std::cout << mIndPtr << std::endl;
const size_t max = ind.max(); // blocking
for(size_t pos = ind.pos(); pos != max; ++pos){
for(size_t pos = mSPos; pos != mMax; ++pos){
//const size_t mnpos = mlast * max + pos;
const size_t mnpos = PosForward<FT>::value(mlast, max, pos);
const ETuple npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
//const FParType npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
const FParType npos(mlast, mExt, pos);
mExpr(mnpos, npos);
}
}
@ -127,20 +129,18 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr, ForType FT>
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast) const
{
const ETuple last;
auto& ind = *mIndPtr;
//std::cout << mIndPtr << std::endl;
const size_t max = ind.max(); // blocking
for(size_t pos = ind.pos(); pos != max; ++pos){
const FParType last;
for(size_t pos = mSPos; pos != mMax; ++pos){
//const size_t mnpos = mlast * max + pos;
const size_t mnpos = PosForward<FT>::value(mlast, max, pos);
const ETuple npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
const size_t mnpos = PosForward<FT>::value(mlast, mMax, pos);
//const FParType npos = std::move( XFPackNum<SIZE-1>::mkPos(pos, mExt, last) );
const FParType npos(mlast, mExt, pos);
mExpr(mnpos, npos);
}
}
template <class IndexClass, class Expr, ForType FT>
typename For<IndexClass,Expr,FT>::ETuple For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
typename For<IndexClass,Expr,FT>::FParType For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
{
return mExpr.rootSteps(iPtrNum);
}