Pseudo member aliases

bearophile bearophileHUGS at lycos.com
Thu Aug 12 05:52:23 PDT 2010


Deokjae:
> Ok, the function func can be called like a member function of a type K[V].
> Is there any way to do similar work on alias?
> Actually I'd like to define aliases ValueType and KeyType on associative 
> arrays and plain arrays, so that they are like member aliases of the 
> array types.
> If it is possible, code like the following would be compiled using them.
> 
> writeln(typeid((string[]).KeyType))); //print "int"
> writeln(typeid((string[]).ValueType))); //print "immutable(char)[]"
> auto x = [1:"hello", 2:"world"];
> writeln(typeid(x.ValueType));//print "immutable(char)[]"

You may create a template that accepts an alias, and contains a static if to tell apart AAs and arrays, and become alias of the key or value type. But then you have to use them with a different syntax, as a normal template.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list