473,395 Members | 1,652 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,395 software developers and data experts.

C++ template metaprogramming in C#?

Joe
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.

Aug 27 '07 #1
7 3430
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe" <jo************@globetrotter.netwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
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.

Aug 27 '07 #2
Joe
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++ ?

Aug 27 '07 #3
Joe
Okay I have my answer.

http://blogs.msdn.com/csharpfaq/arch.../12/88913.aspx
Template metaprogramming
C++ templates are sometimes used for a technique known as template
metaprogramming. There is no way to do this in C#.
;-)

Aug 27 '07 #4
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#?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe" <jo************@globetrotter.netwrote in message
news:11**********************@22g2000hsm.googlegro ups.com...
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++ ?

Aug 27 '07 #5

"Joe" <jo************@globetrotter.netwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
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).
Aug 27 '07 #6
Joe
I am on a project that will consist of many calculations (processor
intensive). Some people let me know that templates are good for it.

Aug 27 '07 #7
Joe,

My apologies. I saw the "template" in "template metaprogramming" and
missed the real intent of your question completely.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Joe" <jo************@globetrotter.netwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
Okay I have my answer.

http://blogs.msdn.com/csharpfaq/arch.../12/88913.aspx
Template metaprogramming
C++ templates are sometimes used for a technique known as template
metaprogramming. There is no way to do this in C#.
;-)

Aug 27 '07 #8

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

Similar topics

0
by: Dave | last post by:
For those who might be so inclined, I was wondering if I might get honest critiques of my first real venture into template metaprogramming. This template metaprogram sorts a list of integers at...
12
by: Dave | last post by:
Would people agree with the statement that to a large degree, using template metaprogramming techniques turns a C++ compiler into a C++ interpreter (but just for the metaprogrammed portions of the...
21
by: Protoman | last post by:
I've been looking at template metaprogramming. It seems really cool, make the compiler do most of the work. I have very simple program that uses TMP,it calculates the square of a number, but it...
5
by: Mark Stijnman | last post by:
I am trying to teach myself template metaprogramming and I have been trying to create lists of related types. I am however stuck when I want to make a template that gives me the last type in a...
9
by: Joe | last post by:
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...
1
by: Ted | last post by:
I have cross posted this to comp.lang.c++ and to sci.math.num- analysis in the belief that the topic is of interest to some in both groups. I am building my toolkit, in support of my efforts in...
5
by: iapx86 | last post by:
My parser project calls for a computed goto (see code below). The C preprocessor delivers the desired result, but is ugly. Template metaprogramming delivers results I do not understand. Can...
3
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey...
12
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.