How to specialize template function for associative arrays?

Regan Heath regan at netmail.co.nz
Fri Oct 19 07:00:15 PDT 2007


Aarti_pl wrote:
> Extrawurst pisze:
>> as far as i know:
>>
>> void parse(T : A[B])() {
>> }
>>
>> ~Extrawurst
>>
>>
> 
> Unfortunately not... I was also thinking that it will work, but you get 
> compile time error instead:
> 
> quicktest.d(13): Error: identifier 'B' is not defined
> quicktest.d(13): Error: index is not a type or an expression
> quicktest.d(13): Error: identifier 'A' is not defined
> quicktest.d(13): Error: A is used as a type
> 
> I managed to catch associative arrays with 'static if' and templates, 
> but it would be better to use template specialization to have better 
> source code structure.
> 
> Any other ideas?

Does parse really have no arguments?  Or does it actally look a bit like:

import std.stdio;

void parse(T)(T t) {
	writefln("parse(T)");
}


void parse(V, K)(V[K] arr) {
	writefln("parse(V, K)");
}

void main() {
	int[char[]] arr;
	parse!(int, char[])(arr);
}

Regan


More information about the Digitalmars-d-learn mailing list