From b1f9a38af747cc70d8166dd8d2bea5fd45ed038a Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 3 Jan 2023 21:02:50 +0100 Subject: [PATCH] mindex: replace type of ipack --- src/include/ranges/index_mul.cc.h | 16 +++++------ src/include/ranges/mrange.cc.h | 47 ++++++++++++++++--------------- src/include/ranges/mrange.h | 12 ++++---- src/tests/range_unit_test.cc | 10 +++---- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/include/ranges/index_mul.cc.h b/src/include/ranges/index_mul.cc.h index d7f61b1..bdf4563 100644 --- a/src/include/ranges/index_mul.cc.h +++ b/src/include/ranges/index_mul.cc.h @@ -16,7 +16,7 @@ namespace CNORXZ Isq is) { static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence"); - return MIndex( std::get(a.pack())..., + return MIndex( a.pack()[std::integral_constant{}]..., std::make_shared(b.THIS()) ); } @@ -27,7 +27,7 @@ namespace CNORXZ { static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence"); return MIndex( std::make_shared(a.THIS()), - std::get(b.pack())... ); + b.pack()[std::integral_constant{}]... ); } template ( std::get(a.pack())..., - std::get(b.pack())... ); + return MIndex( a.pack()[std::integral_constant{}]..., + b.pack()[std::integral_constant{}]... ); } /********************* @@ -51,7 +51,7 @@ namespace CNORXZ const Sptr& b, Isq is) { static_assert(sizeof...(Is) == sizeof...(Indices), "inconsistent index sequence"); - return std::make_shared>( std::get(a->pack())..., b ); + return std::make_shared>( a->pack()[std::integral_constant{}]..., b ); } template @@ -60,7 +60,7 @@ namespace CNORXZ Isq js) { static_assert(sizeof...(Js) == sizeof...(Indices), "inconsistent index sequence"); - return std::make_shared>( a, std::get(b->pack())... ); + return std::make_shared>( a, b->pack()[std::integral_constant{}]... ); } template ( std::get(a->pack())..., - std::get(b->pack())... ); + return MIndex( a->pack()[std::integral_constant{}]..., + b->pack()[std::integral_constant{}]... ); } diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index a38a22e..847155c 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -22,14 +22,14 @@ namespace CNORXZ } template - constexpr decltype(auto) GMIndex::mkLMax(const IndexPack& ipack) + constexpr decltype(auto) GMIndex::mkLMax(const SPack& ipack) { - return iter<0,NI>( [&](auto i) { return std::get(ipack)->lmax(); }, + return iter<0,NI>( [&](auto i) { return ipack[i]->lmax(); }, [](auto... e) { return (e * ...); }); } template - constexpr decltype(auto) GMIndex::mkPMax(const IndexPack& ipack, const FormatT& format) + constexpr decltype(auto) GMIndex::mkPMax(const SPack& ipack, const FormatT& format) { if constexpr(std::is_same::value){ return mkLMax(ipack); @@ -37,7 +37,7 @@ namespace CNORXZ else { return iter<0,NI> ( [&](auto i) - { return (std::get(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::mkPos() { mLex = iter<0,NI> - ([&](auto i) { return std::get(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::value){ IB::mPos = iter<0,NI> - ([&](auto i) { return std::get(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 template - constexpr decltype(auto) GMIndex::mkLexFormat(const IndexPack& ipack, Isq is) + constexpr decltype(auto) GMIndex::mkLexFormat(const SPack& ipack, Isq is) { return gmformat ( iter - ( [&](auto i) { return std::get(ipack)->pmax(); }, + ( [&](auto i) { return ipack[i]->pmax(); }, [](const auto&... as) { return (as * ...); } )..., SPos<1>() ); } @@ -73,8 +73,8 @@ namespace CNORXZ template inline void GMIndex::up() { - std::integral_constant i; - auto& ind = std::get(mIPack); + constexpr std::integral_constant 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 inline void GMIndex::down() { - std::integral_constant i; - auto& ind = std::get(mIPack); + constexpr std::integral_constant 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 constexpr decltype(auto) GMIndex::mkIFor(const Xpr& xpr, F&& f) const { + constexpr std::integral_constant i; if constexpr(I == sizeof...(Indices)-1){ - return std::get(mIPack)->ifor(xpr,std::forward(f)); + return mIPack[i]->ifor(xpr,std::forward(f)); } else { auto f1 = f; auto f2 = f1; - return std::get(mIPack)->ifor( mkIFor( xpr, std::move(f1) ), std::move(f2) ); + return mIPack[i]->ifor( mkIFor( xpr, std::move(f1) ), std::move(f2) ); } } @@ -250,8 +251,8 @@ namespace CNORXZ } if constexpr(not std::is_same::value){ mLex = lexpos; } IB::mPos = iter<0,NI>( [&](auto i) { - *std::get(mIPack) = (lex() / lexFormat()[i].val()) % std::get(mIPack)->lmax().val(); - return format()[i].val() * std::get(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::stepSize(const IndexId& id) const { return iter<0,NI> - ( [&](auto i) { return std::get(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(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{}]->stringMeta() + ( (dlim + xs) + ... ) + elim; } ); } template typename GMIndex::MetaType GMIndex::meta() const { - return iter<0,NI>( [&](auto i) { return std::get(mIPack)->meta(); }, + return iter<0,NI>( [&](auto i) { return mIPack[i]->meta(); }, [](const auto&... xs) { return std::make_tuple(xs...); } ); } template GMIndex& GMIndex::at(const MetaType& metaPos) { - iter<0,NI>( [&](auto i) { std::get(mIPack)->at( std::get(metaPos) ); }, NoF {} ); + iter<0,NI>( [&](auto i) { mIPack[i]->at( std::get(metaPos) ); }, NoF {} ); IB::mPos = iter<0,NI> - ( [&](auto i) { return std::get(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 - const typename GMIndex::IndexPack& GMIndex::pack() const + const SPack& GMIndex::pack() const { return mIPack; } diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index 63da586..51bc994 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -22,7 +22,7 @@ namespace CNORXZ typedef IndexInterface, Tuple> IB; - typedef Tuple...> IndexPack; + //typedef Tuple...> IndexPack; typedef Tuple MetaType; typedef MRange RangeType; static constexpr SizeT NI = sizeof...(Indices); @@ -75,18 +75,18 @@ namespace CNORXZ GMIndex& operator()(const Sptr>& mi); GMIndex& operator()(); - const IndexPack& pack() const; + const SPack& pack() const; const auto& format() const; const auto& lexFormat() const; GMIndex& setFormat(const FormatT& bs); private: template - static constexpr decltype(auto) mkLexFormat(const IndexPack& ipack, Isq is); + static constexpr decltype(auto) mkLexFormat(const SPack& ipack, Isq is); - static constexpr decltype(auto) mkLMax(const IndexPack& ipack); + static constexpr decltype(auto) mkLMax(const SPack& ipack); - static constexpr decltype(auto) mkPMax(const IndexPack& ipack, const FormatT& format); + static constexpr decltype(auto) mkPMax(const SPack& ipack, const FormatT& format); inline void mkPos(); @@ -103,7 +103,7 @@ namespace CNORXZ constexpr decltype(auto) mkIFor(const Xpr& xpr, F&& f) const; Sptr mRange; - IndexPack mIPack; + SPack mIPack; typedef RemoveRef{}))> LexFormatT; LexFormatT mLexFormat; FormatT mFormat; diff --git a/src/tests/range_unit_test.cc b/src/tests/range_unit_test.cc index 74127b2..95a6d38 100644 --- a/src/tests/range_unit_test.cc +++ b/src/tests/range_unit_test.cc @@ -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{}]; + auto ui = xxi.pack()[std::integral_constant{}]; Tuple 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{}]; + auto ui = xxi.pack()[std::integral_constant{}]; + auto ci2 = xxi.pack()[std::integral_constant{}]; Tuple meta(*(*ci1),*(*ui),*(*ci2)); auto meta2 = mkm(cnt); EXPECT_EQ(meta, meta2);