How to specialize template function for associative arrays?
Marcin Kuszczak
aarti_nospam at please_interia.pl
Fri Oct 19 15:11:25 PDT 2007
Extrawurst wrote:
> what about just this :
>
> void foo(A, B)(A[B] _aa)
> {
> foreach(it; _aa)
> {
> writefln("%s",it);
> }
> }
>
> void main()
> {
> string[int] bar = [2:"test"[], 55:"bar"];
>
> foo!(string,int)(bar);
>
> writefln("byye");
> }
>
>
> ~Extrawurst
It will not work. Instantiation should be same for all types...
I found following solution:
void parse(T)() {
static if (isAssociativeArray(T)) {
....
} else {
....
}
}
Template isAssociativeArray(T) is from Tango/core/traits.d. (Thank you,
Tango team!). Thanks to this template I could also get key type and value
type of associative array.
Anyway I think that it should work somehow for specializations, so I will
put enhancement request on bugzilla.
--
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why... I believe in Jesus - http://www.zapytajmnie.com (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
More information about the Digitalmars-d-learn
mailing list