19571, "abhishekingit", "How to write a class method which returns a generic domain where the shape of the domain is unknown at compile time?", "2022-03-30T10:50:11Z"
I was trying to write an overriding class method that returns a domain of any shape but I cannot figure out a way to do so.
I want a way to perform a dynamic dispatch to fetch a generic domain from DerivedChild
as I am fetching values from a Map
.
class AbstractParent {
// less generic fields
const rank: int;
proc init(rank: int) {
this.rank = rank;
}
proc getDomain(): domain {
halt("Pure virutal method");
}
}
class DerivedChild: AbstractParent {
param rank: int;
param stridable: bool;
var dom: domain(rank, stridable = stridable);
proc init(size: domain) {
super.init(size.rank);
this.rank = size.rank;
this.stridable = size.stridable;
this.dom = size;
}
//generic fields
override proc getDomain(): domain {
return this.dom;
}
}
var dataMap: map(string, shared AbstractParent);
var d1: domain(2) = {1..2, 1..3};
var dervChild1 = new shared DerivedChild(d1);
dataMap.add("quantity1", dervChild1);
writeln(dataMap.getValue("quantity1`").getDomain());
With reference to #19570 I was also wondering if there is some workaround that allows us to like downcast AbstractParent
to DerivedChild
and call getDomain()
from there.