im com
This commit is contained in:
parent
6460276bc4
commit
a340bda404
2 changed files with 40 additions and 19 deletions
|
@ -4,9 +4,15 @@
|
|||
|
||||
#include "ranges/rheader.h"
|
||||
#include "xfor.h"
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
namespace {
|
||||
template <class Op>
|
||||
using to_size_t<Op> = size_t;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
struct XFPackNum
|
||||
|
@ -24,7 +30,6 @@ namespace MultiArrayHelper
|
|||
{
|
||||
return XFPackNum<N-1>::mkForTp(iTuple, std::get<N>(iTuple), args...)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -43,7 +48,6 @@ namespace MultiArrayHelper
|
|||
{
|
||||
return XFPackNum<std::tuple_size<IndexTuple>::value-1>::mkFor( std::get<0>(iTuple), args... );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // end namespace MultiArrayHelper
|
||||
|
|
|
@ -4,11 +4,16 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
namespace MultiArrayHelper
|
||||
{
|
||||
namespace {
|
||||
template <class Op>
|
||||
using to_size_t = size_t;
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
template <class IndexClass, class Expr, class... Ops>
|
||||
class For
|
||||
{
|
||||
public:
|
||||
|
@ -17,19 +22,24 @@ namespace MultiArrayHelper
|
|||
For& operator=(For&& in) = default;
|
||||
|
||||
template <typename... Args>
|
||||
For(const std::shared_ptr<IndexClass>& indPtr, const Args&... args);
|
||||
For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
std::tuple<to_size_t<Ops>...>&& ext, const Args&... args);
|
||||
|
||||
For(const std::shared_ptr<IndexClass>& indPtr, Expr&& expr);
|
||||
For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr&& expr, std::tuple<to_size_t<Ops>...>&& ext);
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t mlast, const std::tuple<to_size_t<Ops>...>& last) const;
|
||||
|
||||
private:
|
||||
For() = default;
|
||||
|
||||
std::shared_ptr<IndexClass> mIndPtr;
|
||||
Expr mExpr;
|
||||
mutable std::shared_ptr<IndexClass> mIndPtr;
|
||||
const Expr mExpr;
|
||||
const std::tuple<to_size_t<Ops>...> mExt;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace MultiArrayHelper
|
||||
|
||||
/* ========================= *
|
||||
|
@ -39,22 +49,29 @@ namespace MultiArrayHelper
|
|||
namespace MultiArrayHelper
|
||||
{
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
template <class IndexClass, class Expr, class... Ops>
|
||||
template <typename... Args>
|
||||
For<IndexClass,Expr>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
const Args&... args) : mIndPtr(indPtr), mExpr(args...) {}
|
||||
For<IndexClass,Expr,Ops...>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
std::tuple<to_size_t<Ops>...>&& ext,
|
||||
const Args&... args) :
|
||||
mIndPtr(indPtr), mExpr(args...), mExt(ext) {}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
For<IndexClass,Expr>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr&& expr) : mIndPtr(indPtr), mExpr(expr) {}
|
||||
template <class IndexClass, class Expr, class... Ops>
|
||||
For<IndexClass,Expr,Ops...>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr&& expr, std::tuple<to_size_t<Ops>...>&& ext) :
|
||||
mIndPtr(indPtr), mExpr(expr), mExt(ext) {}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void For<IndexClass,Expr>::operator()(size_t start)
|
||||
template <class IndexClass, class Expr, class... Ops>
|
||||
inline void For<IndexClass,Expr,Ops...>::operator()(size_t mlast,
|
||||
const std::tuple<to_size_t<Ops>...>& last) const
|
||||
{
|
||||
static const size_t opNum = sizeof...(Ops);
|
||||
auto& ind = *mIndPtr;
|
||||
const size_t max = ind.max();
|
||||
for(ind = 0; ind.pos() != max; ++ind){
|
||||
mExpr(start * max + ind.pos()); // CHECK!!
|
||||
const size_t mnpos = mlast * max + ind.pos();
|
||||
const std::tuple<to_size_t<Ops>...> npos( /* !!! fancy code !!! */ );
|
||||
mExpr(mnpos, npos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue