im com while implementing xfor (compiles without instanciating templates)

This commit is contained in:
Christian Zimmermann 2018-01-07 22:33:34 +01:00
parent 85f221f5e1
commit ba86c2f9fa
5 changed files with 62 additions and 0 deletions

View file

@ -88,6 +88,10 @@ namespace MultiArrayTools
std::string id();
void print(size_t offset);
template <class... Exprs>
auto ifor(Exprs&&... exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...));
};
@ -366,6 +370,14 @@ namespace MultiArrayTools
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
template <class... Indices>
template <class... Exprs>
auto ContainerIndex<Indices...>::ifor(Exprs&&... exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...))
{
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...);
}
/*****************************
* ContainerRangeFactory *

View file

@ -103,6 +103,10 @@ namespace MultiArrayTools
std::string id();
void print(size_t offset);
template <class... Exprs>
auto ifor(Exprs&&... exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...));
};
/*************************
@ -410,6 +414,13 @@ namespace MultiArrayTools
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
}
template <class... Indices>
template <class... Exprs>
auto MultiIndex<Indices...>::ifor(Exprs&&... exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...))
{
return RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, exs...);
}
/*************************
* MultiRangeFactory *

View file

@ -219,6 +219,16 @@ namespace MultiArrayHelper
RPackNum<N-1>::buildInfoVec(out, ip, bs);
}
template <class IndexPack, class... Exprs>
static auto mkFor(const IndexPack& ipack, Exprs&&... exs)
-> decltype(std::get<std::tuple_size<IndexPack>::value-N>(ipack)
->ifor(RPackNum<N-1>::template mkFor<IndexPack,Exprs...>
(ipack, exs...) ) )
{
return std::get<std::tuple_size<IndexPack>::value-N>(ipack)
->ifor( RPackNum<N-1>::template mkFor<IndexPack,Exprs...>(ipack, exs...) );
}
};
@ -382,6 +392,13 @@ namespace MultiArrayHelper
out.emplace_back(*std::get<POS>(ip), std::get<POS>(bs));
}
template <class IndexPack, class... Exprs>
static auto mkFor(const IndexPack& ipack, Exprs&&... exs)
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
->ifor(exs...) )
{
return std::get<std::tuple_size<IndexPack>::value-1>(ipack)->ifor(exs...);
}
};

View file

@ -11,6 +11,10 @@
#include "ranges/index_base.h"
#include "ranges/range_base.h"
#include "xfor/xfor.h"
using MultiArrayHelper::For;
namespace MultiArrayTools
{
@ -59,6 +63,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 <typename U, SpaceType TYPE>
@ -239,6 +246,15 @@ namespace MultiArrayTools
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
}
template <typename U, SpaceType TYPE>
template <class Expr>
auto SingleIndex<U,TYPE>::ifor(Expr&& ex) const
-> For<SingleIndex<U,TYPE>,Expr>
{
return For<SingleIndex<U,TYPE>,Expr>
( std::make_shared<SingleIndex<U,TYPE> >(*this), ex );
}
/********************
* SingleRange *

View file

@ -19,6 +19,8 @@ namespace MultiArrayHelper
template <typename... Args>
For(const std::shared_ptr<IndexClass>& indPtr, const Args&... args);
For(const std::shared_ptr<IndexClass>& indPtr, Expr&& expr);
inline void operator()(size_t start = 0);
private:
@ -42,6 +44,10 @@ namespace MultiArrayHelper
For<IndexClass,Expr>::For(const std::shared_ptr<IndexClass>& indPtr,
const Args&... args) : mIndPtr(indPtr), mExpr(args...) {}
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>
inline void For<IndexClass,Expr>::operator()(size_t start)
{