Template instantiation syntax

Walter Bright newshound1 at digitalmars.com
Sat Oct 11 14:35:39 PDT 2008


Dave wrote:
> Still there may be an issue with a<b,c>d, but again that is apparently 
> solved in C#, Java  and C++0x,

In C++, this is resolved by looking 'a' up in the symbol table to see if 
it is a template or not. This means it is impossible to parse C++ 
without doing semantic analysis. Such means it is impossible to write 
*correct* C++ tools that analyze syntax, such as color syntax 
highlighting, without writing most of a full compiler.

(In cases, such as template bodies, where the compiler cannot do 
semantic analysis for parsing, the language requires the 'template' 
keyword be inserted before the 'a'..)

There are a lot of hackish ways to parse C++ 95% correctly, and these 
are often used in editors. But none of them do it 100% unless they are 
backed by a full C++ compiler.

C++ pays a high price for the < >, and still fails to get the job done 
correctly.

I don't know specifically how Java and C# do it, but their generics are 
not true templates, they are only types, and so can only appear in very 
restricted circumstances.



More information about the Digitalmars-d mailing list