anonymous range constructor: promote subrange layer of anonymous range arguments

This commit is contained in:
Christian Zimmermann 2018-07-16 12:58:06 +02:00
parent b9e5d6a898
commit 764bcac758
2 changed files with 26 additions and 7 deletions

View file

@ -131,6 +131,7 @@ namespace MultiArrayTools
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
using namespace MultiArrayTools; using namespace MultiArrayTools;
template <> template <>
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange> rp, inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange> rp,
std::vector<std::shared_ptr<RangeBase> > orig, std::vector<std::shared_ptr<RangeBase> > orig,
@ -142,6 +143,16 @@ namespace MultiArrayHelper
} }
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() ); rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
} }
template <>
inline void setRangeToVec<AnonymousRange>(std::vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<AnonymousRange> r)
{
for(size_t i = 0; i != r->dim(); ++i){
v.insert(v.begin(), r->sub(i));
}
}
} }
namespace MultiArrayTools namespace MultiArrayTools
@ -156,7 +167,7 @@ namespace MultiArrayTools
{ {
mOrig.resize(sizeof...(RangeTypes)); mOrig.resize(sizeof...(RangeTypes));
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig ); RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
RPackNum<sizeof...(RangeTypes)-1>::getSize( origs ); mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
} }
template <class... RangeTypes> template <class... RangeTypes>
@ -166,7 +177,7 @@ namespace MultiArrayTools
auto rst = std::make_tuple(origs...); auto rst = std::make_tuple(origs...);
mOrig.resize(sizeof...(RangeTypes)); mOrig.resize(sizeof...(RangeTypes));
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig ); RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
RPackNum<sizeof...(RangeTypes)-1>::getSize( rst ); mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
} }
template <class Range> template <class Range>

View file

@ -46,13 +46,20 @@ namespace MultiArrayHelper
template <class Range> template <class Range>
void resolveSetRange(std::shared_ptr<Range> rp, std::vector<std::shared_ptr<RangeBase> > orig, inline void resolveSetRange(std::shared_ptr<Range> rp, std::vector<std::shared_ptr<RangeBase> > orig,
size_t origpos, size_t size) size_t origpos, size_t size)
{ {
assert(size == 1); assert(size == 1);
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!! rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
} }
template <class Range>
inline void setRangeToVec(std::vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<Range> r)
{
v.insert(v.begin(), r);
}
template <size_t N> template <size_t N>
struct RPackNum struct RPackNum
{ {
@ -216,10 +223,11 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::shared_ptr<RangeBase> >& v) std::vector<std::shared_ptr<RangeBase> >& v)
{ {
v[N] = std::get<N>(rst); setRangeToVec(v, std::get<N>(rst));
//v[N] = std::get<N>(rst);
RPackNum<N-1>::RangesToVec(rst, v); RPackNum<N-1>::RangesToVec(rst, v);
} }
@ -409,7 +417,7 @@ namespace MultiArrayHelper
} }
template <class... Ranges> template <class... Ranges>
static void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::shared_ptr<RangeBase> >& v) std::vector<std::shared_ptr<RangeBase> >& v)
{ {
v[0] = std::get<0>(rst); v[0] = std::get<0>(rst);