473,320 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Generics vs Templates

So whats the deal here regarding Generics in the 2004 release and templates
currently in C++?

Nov 16 '05 #1
2 3066
Mr.Tickle wrote:
So whats the deal here regarding Generics in the 2004 release and
templates currently in C++?


Of course, details about exactly what will be released in the next major
Visual Studio release have not been made public yet, but we can speculate a
bit.

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.

-cd
Nov 16 '05 #2
"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...

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.


Another difference (going by the MSR paper) is that you cannot create
instances of the type parameter. This prevents idioms like:

stack<vector<T> >

where vector<T> is the underlying implementation used by the stack facade
class. Or:

pool<T>

where the pool class creates and maintains a cache of T objects.

Ken
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: andrew queisser | last post by:
I've read some material on the upcoming Generics for C#. I've seen two types of syntax used for constraints: - direct specification of the interface in the angle brackets - where clauses I...
9
by: Chuck Bowling | last post by:
I assume that 2.0 will be rolled out with VS.NET 2004. Does anybody know if MS is planning to ship an STL package with it?
1
by: Hatim Ali | last post by:
Hi, I've heard about generics in C#(Whidbey) which is much like templates in C++. As per my understanding, since C++ doesn't have universal base class concept so templates are important. Why...
4
by: Michael Sparks | last post by:
I started writing some code with the 2.0 beta compiler, and found out quickly that specialization is not supported with generics. For example, I want to do something like this: class number...
8
by: Chris Dunaway | last post by:
The next version of VS.Net (Whidbey) promises to add generics support to VB. I have a vague remembrance of Templates in C++, but I guess I need a refresher. What will generics allow us to do? ...
17
by: atgraham | last post by:
Here is the "lead C# architect" attempting to impugn C++ templates (bottom of the page). http://www.artima.com/intv/generics2.html (bottom of the page) (Full article begins at...
2
by: Zoran Stipanicev | last post by:
I'm trying to port simple expression template to generics but I get some strange errors. The code is shown below and the errors are: (1) 'l_' : is not a member of 'IExpresion' (2) syntax error :...
11
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
8
by: Gary Brown | last post by:
Hi, When I do the following public class IAmAGeneric<T> { ... public T AMember (T a, T b) { return a + b; }; }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.