casts / wildcards for parametrized types

tx tx at lowtech-labs.org
Thu Aug 1 16:28:00 PDT 2013


Hi All,
Hoping somebody can provide some help here, I have a set of classes
that are similar to the following

class Item{}

class Box(T) : Item {
  T value;
  //  ...
}

//Along with some aliases:

alias Box!(long) LongBox;
alias Box!(char) CharBox;
//etc.



I'd like to have a function that operates on instances of Item, but I
want to specialize the behavior to handle instances of Box
differently. Is there anyway I can upcast Item to Box without
specifying the type parameter? In my case I don't really care about
what T is, just that I'm working with a Box of something. Currently I
have a whole if-else ladder checking to see if I'm working with an
instance of each of the aliases and casting appropriately, but I would
prefer to just write that once. I guess I'm looking for something like
cast(Box). Is this possible?

To put it another way, is there a D equivalent to the Java syntax of Box<?>


-tx

--
tx.lowtech-labs.org / tx at lowtech-labs.org


More information about the Digitalmars-d-learn mailing list