urange: allow casts from multi-dim range to sizeT urange

This commit is contained in:
Christian Zimmermann 2024-07-08 16:31:07 +02:00
parent 3835859a5e
commit f0401e50bf

View file

@ -393,7 +393,19 @@ namespace CNORXZ
static inline Sptr<URange<MetaT>> cast(const RangePtr& r)
{
static_assert(std::is_fundamental<MetaT>::value, "got non-fundamental type");
if constexpr(std::is_same<SizeT,MetaT>::value){
if(r->dim() > 1){
Vector<MetaT> v(r->size());
for(SizeT i = 0; i != v.size(); ++i) {
v[i] = i;
}
return std::dynamic_pointer_cast<URange<SizeT>>
( URangeFactory<SizeT>(std::move(v)).create() );
}
}
else {
CXZ_ASSERT(r->dim() == 1, "range cast into URange<Int>: source range must have dim = 1, got " << r->dim());
}
Sptr<URange<MetaT>> o = nullptr;
// TODO: cast from CRange!!!
o = transform<SizeT>(r); if(o) return o;