Compiler as dll

Nick Sabalausky a at a.a
Wed Jan 28 10:53:14 PST 2009


"grauzone" <none at example.net> wrote in message 
news:glphtn$g0f$1 at digitalmars.com...
> Daniel Keep wrote:
>>
>> Templates are a different matter, but then C++ has the same problem.
>> Whether or not you want to release your templates as part of the SDK
>> really depends on what they are.  Templates + interfaces make a good 
>> pair.
>
> Sure. Bytecode based languages like C# still can export compiled generics, 
> though. Of course, they are not as flexible as D or C++ templates.
>

AIUI, C#'s ability to export compiled generics forced the generics to be 
designed in such a way that objects of the generic type 'T' can only be used 
in ways explicitly allowed by T's explicit constraints. For instance, 
performing a comparison on an object of type T is a compile-time error 
unless the programmer places a constraint on T that T must be something that 
implements the IComparable interface (which includes all of the primitives).

As far as I can tell, the only limitation this inherently forces on generics 
is that the language/library must provide a constraint for anything that a 
template is able to do. The main part where this *really* gimps C#'s 
generics is just simply MS's constant refusal to provide either an 
IArithmetic counterpart to IComparable or individual operator constraints.

In other words, I'm not certain that the lack of flexibility in C#'s 
generics is an inherent consequence of its compiled generics being 
exportable. 





More information about the Digitalmars-d mailing list