473,583 Members | 3,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generics vs Templates

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

Nov 16 '05 #1
2 3094
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******@nospa m.mvps.org> wrote in message
news:ex******** ******@TK2MSFTN GP10.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
3983
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 looked at the files in the Gyro download but I couldn't find any mention of constraints. Can anyone enlighten me what the current status is and what we...
9
3024
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
1432
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 templates are important in C# when everything in C# ultimately derives from class "object". For example, I can build a collection class for type...
4
9189
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 ... class integer : number ... class real : number ... class multiplier<_number> where _number : number ... class multiplier<_number> where _number...
8
3363
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? How do they make coding easier? Is there a resource that will give me a basic understanding of what generics are and how generics will be useful...
17
1924
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 http://www.artima.com/intv/generics.html) I think every employee at Micrsoft must be required to take a class in "FUD marketing" before speaking with anyone outside...
2
1250
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 : '(' generic <class Lhs, class Rhs> where Lhs:IExpresion where Rhs:IExpresion ref struct Expression : public DotNetMat::IExpresion
11
2484
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 provide an implemation of the operator +. Now I want to write another generic class Plan<DType>, which can
8
2546
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
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7929
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.