diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 875b06d..af19563 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -651,6 +651,17 @@ namespace CNORXZ return MRangeFactory(std::make_tuple(rs...)).create(); } + template + Sptr> RangeCast>::func(const RangePtr& r) + { + CXZ_ASSERT(r->dim() == sizeof...(Ranges), "expect range of dimension " + << sizeof...(Ranges) << ", got " << r->dim()); + return std::dynamic_pointer_cast>( MRangeFactory + ( iter<0,sizeof...(Ranges)> + ( [&](auto i) { + return rangeCast>::type> (r->sub(i)); }, + [](const auto&... e){ return std::make_tuple( e... ); } ) ).create() ); + } } #endif diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index b249167..ec7a831 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -203,6 +203,12 @@ namespace CNORXZ template RangePtr mrange(const Sptr&... rs); + + template + struct RangeCast> + { + static Sptr> func(const RangePtr& r); + }; } #endif