mindex: replace type of ipack

This commit is contained in:
Christian Zimmermann 2023-01-03 21:02:50 +01:00
parent 8787ec7590
commit b1f9a38af7
4 changed files with 43 additions and 42 deletions

View file

@ -16,7 +16,7 @@ namespace CNORXZ
Isq<Is...> is)
{
static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( std::get<Is>(a.pack())...,
return MIndex<Indices...,I>( a.pack()[std::integral_constant<SizeT,Is>{}]...,
std::make_shared<I>(b.THIS()) );
}
@ -27,7 +27,7 @@ namespace CNORXZ
{
static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
return MIndex<Indices...,I>( std::make_shared<I>(a.THIS()),
std::get<Js>(b.pack())... );
b.pack()[std::integral_constant<SizeT,Js>{}]... );
}
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
@ -38,8 +38,8 @@ namespace CNORXZ
{
static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
return MIndex<Indices1...,Indices2...>( std::get<Is>(a.pack())...,
std::get<Js>(b.pack())... );
return MIndex<Indices1...,Indices2...>( a.pack()[std::integral_constant<SizeT,Is>{}]...,
b.pack()[std::integral_constant<SizeT,Js>{}]... );
}
/*********************
@ -51,7 +51,7 @@ namespace CNORXZ
const Sptr<I>& b, Isq<Is...> is)
{
static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence");
return std::make_shared<MIndex<Indices...,I>>( std::get<Is>(a->pack())..., b );
return std::make_shared<MIndex<Indices...,I>>( a->pack()[std::integral_constant<SizeT,Is>{}]..., b );
}
template <class BlockT, class... Indices, class I, typename Meta, SizeT... Js>
@ -60,7 +60,7 @@ namespace CNORXZ
Isq<Js...> js)
{
static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence");
return std::make_shared<MIndex<I,Indices...>>( a, std::get<Js>(b->pack())... );
return std::make_shared<MIndex<I,Indices...>>( a, b->pack()[std::integral_constant<SizeT,Js>{}]... );
}
template <class BlockT1, class... Indices1, class BlockT2, class... Indices2,
@ -71,8 +71,8 @@ namespace CNORXZ
{
static_assert(sizeof...(Is) == sizeof...(Indices1), "inconsistent index sequence");
static_assert(sizeof...(Js) == sizeof...(Indices2), "inconsistent index sequence");
return MIndex<Indices1...,Indices2...>( std::get<Is>(a->pack())...,
std::get<Js>(b->pack())... );
return MIndex<Indices1...,Indices2...>( a->pack()[std::integral_constant<SizeT,Is>{}]...,
b->pack()[std::integral_constant<SizeT,Js>{}]... );
}

View file

@ -22,14 +22,14 @@ namespace CNORXZ
}
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLMax(const IndexPack& ipack)
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLMax(const SPack<Indices...>& ipack)
{
return iter<0,NI>( [&](auto i) { return std::get<i>(ipack)->lmax(); },
return iter<0,NI>( [&](auto i) { return ipack[i]->lmax(); },
[](auto... e) { return (e * ...); });
}
template <class FormatT, class... Indices>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkPMax(const IndexPack& ipack, const FormatT& format)
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkPMax(const SPack<Indices...>& ipack, const FormatT& format)
{
if constexpr(std::is_same<FormatT,None>::value){
return mkLMax(ipack);
@ -37,7 +37,7 @@ namespace CNORXZ
else {
return iter<0,NI>
( [&](auto i)
{ return (std::get<i>(ipack)->pmax() - SPos<1>()) * format[i]; },
{ return (ipack[i]->pmax() - SPos<1>()) * format[i]; },
[](auto... e) { return (e + ...); }) + SPos<1>();
}
}
@ -46,11 +46,11 @@ namespace CNORXZ
inline void GMIndex<FormatT,Indices...>::mkPos()
{
mLex = iter<0,NI>
([&](auto i) { return std::get<i>(mIPack)->lex() * mLexFormat[i].val(); },
([&](auto i) { return mIPack[i]->lex() * mLexFormat[i].val(); },
[](const auto&... e) { return (e + ...); });
if constexpr(not std::is_same<FormatT,None>::value){
IB::mPos = iter<0,NI>
([&](auto i) { return std::get<i>(mIPack)->pos() * mFormat[i].val(); },
([&](auto i) { return mIPack[i]->pos() * mFormat[i].val(); },
[](const auto&... e) { return (e + ...); });
}
else {
@ -60,11 +60,11 @@ namespace CNORXZ
template <class FormatT, class... Indices>
template <SizeT... Is>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLexFormat(const IndexPack& ipack, Isq<Is...> is)
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkLexFormat(const SPack<Indices...>& ipack, Isq<Is...> is)
{
return gmformat
( iter<Is,NI>
( [&](auto i) { return std::get<i>(ipack)->pmax(); },
( [&](auto i) { return ipack[i]->pmax(); },
[](const auto&... as) { return (as * ...); } )...,
SPos<1>() );
}
@ -73,8 +73,8 @@ namespace CNORXZ
template <SizeT I>
inline void GMIndex<FormatT,Indices...>::up()
{
std::integral_constant<SizeT,I> i;
auto& ind = std::get<I>(mIPack);
constexpr std::integral_constant<SizeT,I> i;
auto& ind = mIPack[i];
if constexpr(I != 0){
if(ind->lex() == ind->lmax().val()-1){
IB::mPos -= format()[i].val() * ind->pos();
@ -97,8 +97,8 @@ namespace CNORXZ
template <SizeT I>
inline void GMIndex<FormatT,Indices...>::down()
{
std::integral_constant<SizeT,I> i;
auto& ind = std::get<I>(mIPack);
constexpr std::integral_constant<SizeT,I> i;
auto& ind = mIPack[i];
if constexpr(I != 0){
if(ind->lex() == 0){
(*ind) = ind->lmax().val()-1;
@ -121,13 +121,14 @@ namespace CNORXZ
template <SizeT I, class Xpr, class F>
constexpr decltype(auto) GMIndex<FormatT,Indices...>::mkIFor(const Xpr& xpr, F&& f) const
{
constexpr std::integral_constant<SizeT,I> i;
if constexpr(I == sizeof...(Indices)-1){
return std::get<I>(mIPack)->ifor(xpr,std::forward<F>(f));
return mIPack[i]->ifor(xpr,std::forward<F>(f));
}
else {
auto f1 = f;
auto f2 = f1;
return std::get<I>(mIPack)->ifor( mkIFor<I+1>( xpr, std::move(f1) ), std::move(f2) );
return mIPack[i]->ifor( mkIFor<I+1>( xpr, std::move(f1) ), std::move(f2) );
}
}
@ -250,8 +251,8 @@ namespace CNORXZ
}
if constexpr(not std::is_same<FormatT,None>::value){ mLex = lexpos; }
IB::mPos = iter<0,NI>( [&](auto i) {
*std::get<i>(mIPack) = (lex() / lexFormat()[i].val()) % std::get<i>(mIPack)->lmax().val();
return format()[i].val() * std::get<i>(mIPack)->pos();
*mIPack[i] = (lex() / lexFormat()[i].val()) % mIPack[i]->lmax().val();
return format()[i].val() * mIPack[i]->pos();
}, [](const auto&... e) { return (e + ...); } );
return *this;
}
@ -374,7 +375,7 @@ namespace CNORXZ
decltype(auto) GMIndex<FormatT,Indices...>::stepSize(const IndexId<I>& id) const
{
return iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->stepSize(id) * format()[i]; },
( [&](auto i) { return mIPack[i]->stepSize(id) * format()[i]; },
[](const auto&... ss) { return ( ss + ... ); });
}
@ -385,25 +386,25 @@ namespace CNORXZ
const String elim = ")";
const String dlim = ",";
return iter<1,NI>
( [&](auto i) { return std::get<i>(mIPack)->stringMeta(); },
( [&](auto i) { return mIPack[i]->stringMeta(); },
[&](const auto&... xs) {
return blim + std::get<0>(mIPack)->stringMeta() + ( (dlim + xs) + ... ) + elim;
return blim + mIPack[std::integral_constant<SizeT,0>{}]->stringMeta() + ( (dlim + xs) + ... ) + elim;
} );
}
template <class FormatT, class... Indices>
typename GMIndex<FormatT,Indices...>::MetaType GMIndex<FormatT,Indices...>::meta() const
{
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->meta(); },
return iter<0,NI>( [&](auto i) { return mIPack[i]->meta(); },
[](const auto&... xs) { return std::make_tuple(xs...); } );
}
template <class FormatT, class... Indices>
GMIndex<FormatT,Indices...>& GMIndex<FormatT,Indices...>::at(const MetaType& metaPos)
{
iter<0,NI>( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); }, NoF {} );
iter<0,NI>( [&](auto i) { mIPack[i]->at( std::get<i>(metaPos) ); }, NoF {} );
IB::mPos = iter<0,NI>
( [&](auto i) { return std::get<i>(mIPack)->pos()*format()[i].val(); },
( [&](auto i) { return mIPack[i]->pos()*format()[i].val(); },
[](const auto&... xs) { return (xs + ...); });
return *this;
}
@ -431,7 +432,7 @@ namespace CNORXZ
}
template <class FormatT, class... Indices>
const typename GMIndex<FormatT,Indices...>::IndexPack& GMIndex<FormatT,Indices...>::pack() const
const SPack<Indices...>& GMIndex<FormatT,Indices...>::pack() const
{
return mIPack;
}

View file

@ -22,7 +22,7 @@ namespace CNORXZ
typedef IndexInterface<GMIndex<FormatT,Indices...>,
Tuple<typename Indices::MetaType...>> IB;
typedef Tuple<Sptr<Indices>...> IndexPack;
//typedef Tuple<Sptr<Indices>...> IndexPack;
typedef Tuple<typename Indices::MetaType...> MetaType;
typedef MRange<typename Indices::RangeType...> RangeType;
static constexpr SizeT NI = sizeof...(Indices);
@ -75,18 +75,18 @@ namespace CNORXZ
GMIndex& operator()(const Sptr<MIndex<Indices...>>& mi);
GMIndex& operator()();
const IndexPack& pack() const;
const SPack<Indices...>& pack() const;
const auto& format() const;
const auto& lexFormat() const;
GMIndex& setFormat(const FormatT& bs);
private:
template <SizeT... Is>
static constexpr decltype(auto) mkLexFormat(const IndexPack& ipack, Isq<Is...> is);
static constexpr decltype(auto) mkLexFormat(const SPack<Indices...>& ipack, Isq<Is...> is);
static constexpr decltype(auto) mkLMax(const IndexPack& ipack);
static constexpr decltype(auto) mkLMax(const SPack<Indices...>& ipack);
static constexpr decltype(auto) mkPMax(const IndexPack& ipack, const FormatT& format);
static constexpr decltype(auto) mkPMax(const SPack<Indices...>& ipack, const FormatT& format);
inline void mkPos();
@ -103,7 +103,7 @@ namespace CNORXZ
constexpr decltype(auto) mkIFor(const Xpr& xpr, F&& f) const;
Sptr<RangeType> mRange;
IndexPack mIPack;
SPack<Indices...> mIPack;
typedef RemoveRef<decltype(mkLexFormat(mIPack,Isqr<0,NI-1>{}))> LexFormatT;
LexFormatT mLexFormat;
FormatT mFormat;

View file

@ -194,8 +194,8 @@ namespace
for(auto xxi = mrx->begin(); xxi != endxxi; ++xxi){
EXPECT_EQ(xxi.pos(), cnt);
EXPECT_EQ(xxi.lex(), cnt);
auto ci = std::get<0>(xxi.pack());
auto ui = std::get<1>(xxi.pack());
auto ci = xxi.pack()[std::integral_constant<SizeT,0>{}];
auto ui = xxi.pack()[std::integral_constant<SizeT,1>{}];
Tuple<SizeT,String> meta(*(*ci),*(*ui));
auto meta2 = mkm(cnt);
EXPECT_EQ(meta, meta2);
@ -252,9 +252,9 @@ namespace
for(auto xxi = mrx->begin(); xxi != endxxi; ++xxi){
EXPECT_EQ(xxi.pos(), cnt);
EXPECT_EQ(xxi.lex(), cnt);
auto ci1 = std::get<0>(xxi.pack());
auto ui = std::get<1>(xxi.pack());
auto ci2 = std::get<2>(xxi.pack());
auto ci1 = xxi.pack()[std::integral_constant<SizeT,0>{}];
auto ui = xxi.pack()[std::integral_constant<SizeT,1>{}];
auto ci2 = xxi.pack()[std::integral_constant<SizeT,2>{}];
Tuple<SizeT,String,SizeT> meta(*(*ci1),*(*ui),*(*ci2));
auto meta2 = mkm(cnt);
EXPECT_EQ(meta, meta2);