From 3b36f96bfa13d1a57258162f77f9a3a64f35f0ff Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 9 Jan 2018 11:37:26 +0100 Subject: [PATCH] im com --- src/ranges/single_range.h | 13 ++++----- src/xfor/for_utils.h | 41 ++++++++++++++++++++++++++++ src/xfor/index_for_utils.h | 55 -------------------------------------- src/xfor/xfor.h | 7 ++--- 4 files changed, 50 insertions(+), 66 deletions(-) create mode 100644 src/xfor/for_utils.h delete mode 100644 src/xfor/index_for_utils.h diff --git a/src/ranges/single_range.h b/src/ranges/single_range.h index a825531..40f6fea 100644 --- a/src/ranges/single_range.h +++ b/src/ranges/single_range.h @@ -64,8 +64,9 @@ namespace MultiArrayTools std::string id(); void print(size_t offset); - template - auto ifor(Expr&& ex) const -> For,Expr>; + template + auto ifor(std::tuple...>&& ee, Expr&& ex) const + -> For,Expr,Ops...>; }; template @@ -247,12 +248,12 @@ namespace MultiArrayTools } template - template - auto SingleIndex::ifor(Expr&& ex) const - -> For,Expr> + template + auto SingleIndex::ifor(std::tuple...>&& ee, Expr&& ex) const + -> For,Expr,Ops...> { return For,Expr> - ( std::make_shared >(*this), ex ); + ( std::make_shared >(*this), ex, ee ); } diff --git a/src/xfor/for_utils.h b/src/xfor/for_utils.h new file mode 100644 index 0000000..05f577d --- /dev/null +++ b/src/xfor/for_utils.h @@ -0,0 +1,41 @@ + +#ifndef __for_utils_h__ +#define __for_utils_h__ + +#include "ranges/rheader.h" +#include +#include + +namespace MultiArrayHelper +{ + namespace { + template + using to_size_t = size_t; + } + + template + struct XFPackNum + { + template + static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args) + -> decltype(XFPackNum::mkPos(et, lt, 0ul, args...)) + { + return XFPackNum::mkPos(et, lt, std::get(lt) + ind.pos() * std::get(et), args...); + } + }; + + template <> + struct XFPackNum<0> + { + template + static auto mkPos(const IndexClass& ind, const ExtTuple& et, const LastTuple& lt, const Args&... args) + -> std::tuple...> + { + return std::tuple...>(std::get<0>(lt) + ind.pos() * std::get<0>(et), args...); + } + + }; + +} // end namespace MultiArrayHelper + +#endif diff --git a/src/xfor/index_for_utils.h b/src/xfor/index_for_utils.h deleted file mode 100644 index cc8145d..0000000 --- a/src/xfor/index_for_utils.h +++ /dev/null @@ -1,55 +0,0 @@ - -#ifndef __index_for_utils_h__ -#define __index_for_utils_h__ - -#include "ranges/rheader.h" -#include "xfor.h" -#include -#include - -namespace MultiArrayHelper -{ - namespace { - template - using to_size_t = size_t; - } - - template - struct XFPackNum - { - template - static auto mkFor(const std::shared_ptr& iPtr, const Args&... args) - -> For::mkFor(args...))> - { - return For::mkFor(args...))>(iPtr, args...); - } - - template - static auto mkForTp(const IndexTuple& iTuple, const Args&... args) - -> decltype(XFPackNum::mkForTp(std::get(iTuple), args...)) - { - return XFPackNum::mkForTp(iTuple, std::get(iTuple), args...) - } - }; - - template <> - struct XFPackNum<0> - { - template - static auto mkFor(const std::shared_ptr& iPtr, const Args&... args) - -> For - { - return For(iPtr, args...); - } - - template - static auto mkForTp(const IndexTuple& iTuple, const Args&... args) - -> decltype(XFPackNum::value-1>::mkFor( std::get<0>(iTuple), args... )) - { - return XFPackNum::value-1>::mkFor( std::get<0>(iTuple), args... ); - } - }; - -} // end namespace MultiArrayHelper - -#endif diff --git a/src/xfor/xfor.h b/src/xfor/xfor.h index 4499b06..1dd9099 100644 --- a/src/xfor/xfor.h +++ b/src/xfor/xfor.h @@ -5,13 +5,10 @@ #include #include #include +#include "xfor/for_utils.h" namespace MultiArrayHelper { - namespace { - template - using to_size_t = size_t; - } template 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...> npos( /* !!! fancy code !!! */ ); + const std::tuple...> npos = std::move( XFPackNum::mkPos(ind, mExt, last) ); mExpr(mnpos, npos); } }