other array types than char in templates?

Don Clugston dac at nospam.com.au
Tue May 29 23:30:20 PDT 2007


Daniel Keep wrote:
> 
> dennis luehring wrote:
>> what is the reason for allowing this
>>
>> template test(char[] bla)
>> {
>> ....
>> }
>>
>>
>> but not
>>
>> template test(int[] bla)
>> {
>> ....
>> }
>>
>> or other bultin(own) types?
>>
>> ciao dennis
> 
> I think it's because arguments to a template become part of its mangled
> name.
Yes.
 >  Integers and floats are easy, as are actual strings, but to
> support arbitrary types, Walter would either need some kind of generic
> serialisation setup, or find a new way of mangling templates.

That's not much of an issue. In fact, if you look at the ABI page, 
you'll see that the mangling scheme almost supports arbitrary types already.

TemplateArg:
     T Type
     V Type Value
     S LName
Any type which can be a type template parameter, and which has literals, 
could also be a value parameter.

The problem is that the mangled names become too long, which makes bad 
things happen (eg, the obj file format imposes a maximum identifier 
length of ~ 3kB).
There a few types (int[], short[] ubyte[]) which are essentially 
identical to the permitted dchar[], wchar[], char[], and could trivially 
be permitted.

CTFE has drastically reduced the number of cases where it would be 
useful, though.



More information about the Digitalmars-d mailing list