CompilerTech

导航

generic or template

If you compare the CLR generics proposed by Microsoft Research (see
http://research.microsoft.com/projec...n/generics.pdf) to C++
templates, you'll find some differences:

* CLR Generics are supported in the CLR, with instantiation occuring at
runtime. Full metadata exists for the generic type, and generic
instantiations can be reflected upon through meta-data.

* C++ Templates are a compile-time only mechanism. C++ template
instantiations are ordinary classes with extraordinary names. When compiled
to managed code, each template is a distinct .NET class, and the
meta-relationship between those classes is not represented in the metadata
anywhere.

* C++ templates support partial specialization. There's nothing comparable
in CLR Generics.

* CLR Generics support type constraints on generic parameters. There's
nothing comparable in C++ templates (although it's possible to synthesize
similar mechanisms in some cases).

* C++ Templates are a Turing-complete functional language that's executed by
the compiler. CLR Generics are simply generic types.

posted on 2011-09-02 15:32  compilerTech  阅读(227)  评论(0编辑  收藏  举报