This commit is contained in:
Christian Zimmermann 2018-01-09 11:37:26 +01:00
parent a340bda404
commit 3b36f96bfa
4 changed files with 50 additions and 66 deletions

View file

@ -64,8 +64,9 @@ namespace MultiArrayTools
std::string id();
void print(size_t offset);
template <class Expr>
auto ifor(Expr&& ex) const -> For<SingleIndex<U,TYPE>,Expr>;
template <class Expr, class... Ops>
auto ifor(std::tuple<to_size_t<Ops>...>&& ee, Expr&& ex) const
-> For<SingleIndex<U,TYPE>,Expr,Ops...>;
};
template <typename U, SpaceType TYPE>
@ -247,12 +248,12 @@ namespace MultiArrayTools
}
template <typename U, SpaceType TYPE>
template <class Expr>
auto SingleIndex<U,TYPE>::ifor(Expr&& ex) const
-> For<SingleIndex<U,TYPE>,Expr>
template <class Expr, class... Ops>
auto SingleIndex<U,TYPE>::ifor(std::tuple<to_size_t<Ops>...>&& ee, Expr&& ex) const
-> For<SingleIndex<U,TYPE>,Expr,Ops...>
{
return For<SingleIndex<U,TYPE>,Expr>
( std::make_shared<SingleIndex<U,TYPE> >(*this), ex );
( std::make_shared<SingleIndex<U,TYPE> >(*this), ex, ee );
}

41
src/xfor/for_utils.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef __for_utils_h__
#define __for_utils_h__
#include "ranges/rheader.h"
#include <array>
#include <tuple>
namespace MultiArrayHelper
{
namespace {
template <class Op>
using to_size_t = size_t;
}
template <size_t N>
struct XFPackNum
{
template <class IndexClass, class ExtTuple, class LastTuple, typename... Args>
static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args)
-> decltype(XFPackNum<N-1>::mkPos(et, lt, 0ul, args...))
{
return XFPackNum<N-1>::mkPos(et, lt, std::get<N>(lt) + ind.pos() * std::get<N>(et), args...);
}
};
template <>
struct XFPackNum<0>
{
template <class IndexClass, class ExtTuple, class LastTuple, typename... Args>
static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args)
-> std::tuple<size_t,to_size_t<Args>...>
{
return std::tuple<size_t,to_size_t<Args>...>(std::get<0>(lt) + ind.pos() * std::get<0>(et), args...);
}
};
} // end namespace MultiArrayHelper
#endif

View file

@ -1,55 +0,0 @@
#ifndef __index_for_utils_h__
#define __index_for_utils_h__
#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
{
template <class Expr, class IndexClass, typename... Args>
static auto mkFor(const std::shared_ptr<IndexClass>& iPtr, const Args&... args)
-> For<IndexClass,decltype(XFPackNum<N-1>::mkFor<Expr>(args...))>
{
return For<IndexClass,decltype(XFPackNum<N-1>::mkFor<Expr>(args...))>(iPtr, args...);
}
template <class Expr, class IndexTuple, typename... Args>
static auto mkForTp(const IndexTuple& iTuple, const Args&... args)
-> decltype(XFPackNum<N-1>::mkForTp(std::get<N>(iTuple), args...))
{
return XFPackNum<N-1>::mkForTp(iTuple, std::get<N>(iTuple), args...)
}
};
template <>
struct XFPackNum<0>
{
template <class Expr, class IndexClass, typename... Args>
static auto mkFor(const std::shared_ptr<IndexClass>& iPtr, const Args&... args)
-> For<IndexClass,Expr>
{
return For<IndexClass,Expr>(iPtr, args...);
}
template <class Expr, class IndexTuple, typename... Args>
static auto mkForTp(const IndexTuple& iTuple, const Args&... args)
-> decltype(XFPackNum<std::tuple_size<IndexTuple>::value-1>::mkFor( std::get<0>(iTuple), args... ))
{
return XFPackNum<std::tuple_size<IndexTuple>::value-1>::mkFor( std::get<0>(iTuple), args... );
}
};
} // end namespace MultiArrayHelper
#endif

View file

@ -5,13 +5,10 @@
#include <cstdlib>
#include <memory>
#include <tuple>
#include "xfor/for_utils.h"
namespace MultiArrayHelper
{
namespace {
template <class Op>
using to_size_t = size_t;
}
template <class IndexClass, class Expr, class... Ops>
class For
@ -70,7 +67,7 @@ namespace MultiArrayHelper
const size_t max = ind.max();
for(ind = 0; ind.pos() != max; ++ind){
const size_t mnpos = mlast * max + ind.pos();
const std::tuple<to_size_t<Ops>...> npos( /* !!! fancy code !!! */ );
const std::tuple<to_size_t<Ops>...> npos = std::move( XFPackNum<opNum-1>::mkPos(ind, mExt, last) );
mExpr(mnpos, npos);
}
}