C++ template metaprogramming in C#?

  • Thread starter Thread starter Joe
  • Start date Start date
Joe,

While template programming isn't available in .NET, something similar is
available. Lookup Generics (in the context of .NET) and you should find a
great deal of information.

There are differences between them, but definitely enough similarities
to qualify for the comparison.
 
Yes. I know Generics. For now I use it to declare typesafe collections
of objects. Then from what you saying I can use it to do the same (or
close) to template metaprogramming in C++ ?
 
Joe said:
Hi,

I found a concept named template metaprogramming that can be used in C+
+ code at compile-time. I am a beginner at C++. But I am a programmer
on the .NET platform. Do you know if template metaprogramming is
supported in C# (.NET)? For reference I found it:
http://en.wikipedia.org/wiki/Template_metaprogramming.

Thanks to all.

No, there is absolutely nothing similar to template metaprogramming in .NET.
Template metaprogramming relies on specializations which generics do not
have.

OTOH, .NET makes it very easy to generate code on the fly via
Reflection.Emit. Performance is not likely to be as good as template
programs run through the C++ compiler (in fact C++ templates are much more
performant than .NET generics even for collection classes, because the C++
compiler will optimize per type and the .NET JIT creates one shared generic
implementation for all reference types).
 
Well, you can't do all of the things that you can do with templates in
C++. Parameterizing templates with values other than types, for example, is
not supported.

Is there something specific you are trying to do with templates that you
can't do in C#?
 
I am on a project that will consist of many calculations (processor
intensive). Some people let me know that templates are good for it.
 
Joe,

My apologies. I saw the "template" in "template metaprogramming" and
missed the real intent of your question completely.
 
Back
Top