473,883 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why and when Template Metaprogramming

I understand that template metaprogramming is a technique that allows for
calcualations to occur at compile-time rather than run-time.

Can someone explain what is the benefit of this, and when it is good to
employ Template Metaprogramming ?

Jul 23 '05 #1
9 1583


Rock Johnson wrote:
I understand that template metaprogramming is a technique that allows for
calcualations to occur at compile-time rather than run-time.

Can someone explain what is the benefit of this, and when it is good to
employ Template Metaprogramming ?


I think there is a good answer for this in Alexanrescu's "Modern C++
Design".

Reagrds,
Vyacheslav

Jul 23 '05 #2
Rock Johnson wrote:
I understand that template metaprogramming is a technique that allows for
calcualations to occur at compile-time rather than run-time.

Can someone explain what is the benefit of this, and when it is good to
employ Template Metaprogramming ?


TMP is most useful when you want to impress others and show them how
smart and clever you are. No practical use of TMP is known yet (not
even at Boost).

Jul 23 '05 #3
Rapscallion wrote:
[redacted]


We get it. You don't like templates.

PLONK.
Jul 23 '05 #4
ben
> We get it. You don't like templates.

PLONK.


As for me, I like templates. But if I have a choice between two solutions, I
prefer the more flexible and explicit one.

ben
Jul 23 '05 #5
red floyd wrote:
We get it. You don't like templates.


I don't like bloat, macro-, OO-, and template-bloat. OTOH, I like (a)
KISS.

Jul 23 '05 #6
Rapscallion trolled (again):
Rock Johnson wrote:
I understand that template metaprogramming is a technique that
allows for calcualations to occur at compile-time rather than
run-time.

Can someone explain what is the benefit of this, and when it is good
to employ Template Metaprogramming ?
TMP is most useful when you want to impress others and show them how
smart and clever you are.


Ok, ok, we know (and don't care) that you don't like templates - you've been serial-trolling this ng long enough that we
get the point.
No practical use of TMP is known yet (not
even at Boost).


Not so; here's one:

http://www.oonumerics.org/blitz/

It is big and it is clever.

--
Lionel B

Jul 23 '05 #7
Lionel B wrote:
Rapscallion trolled (again):
Rock Johnson wrote:
I understand that template metaprogramming is a technique that
allows for calcualations to occur at compile-time rather than
run-time.

Can someone explain what is the benefit of this, and when it is good
to employ Template Metaprogramming ?


TMP is most useful when you want to impress others and show them how
smart and clever you are.


Ok, ok, we know (and don't care) that you don't like templates - you've
been serial-trolling this ng long enough that we get the point.
No practical use of TMP is known yet (not
even at Boost).


Not so; here's one:

http://www.oonumerics.org/blitz/

It is big and it is clever.


Have you ever used that beast? I have. It makes your life a lot easier. You
come to work, make changes to your program, type 'make' and you are free
for the rest of the day. If the boss asks, "it's compiling".
Jul 23 '05 #8
alex goldman wrote:
Lionel B wrote:
Rapscallion trolled (again):
Rock Johnson wrote:
I understand that template metaprogramming is a technique that
allows for calcualations to occur at compile-time rather than
run-time.

Can someone explain what is the benefit of this, and when it is
good to employ Template Metaprogramming ?

TMP is most useful when you want to impress others and show them how
smart and clever you are.
Ok, ok, we know (and don't care) that you don't like templates -
you've been serial-trolling this ng long enough that we get the
point.
No practical use of TMP is known yet (not
even at Boost).


Not so; here's one:

http://www.oonumerics.org/blitz/

It is big and it is clever.


Have you ever used that beast? I have.


Yup, some while ago.
It makes your life a lot
easier. You come to work, make changes to your program, type 'make'
and you are free for the rest of the day. If the boss asks, "it's
compiling".


:-)

Don't know what compiler you use... it's not quite so bad as I remember it.

--
Lionel B

Jul 23 '05 #9
Rock Johnson wrote:
I understand that template metaprogramming is a technique that allows for
calcualations to occur at compile-time rather than run-time.

Can someone explain what is the benefit of this, and when it is good to
employ Template Metaprogramming ?


Hi.
In game development it's sometimes useful to have consts for some sin,
cos and other values. And speed is of course highest priority. If you
don't want to use paper math tables you can write your own trigonometric
functions as meta templates and use any const value you want. It will
calculate at compile time. It may be useful :-)

misiek
Jul 23 '05 #10

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

Similar topics

0
1261
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 compile time. It works, but if my approach is more awkward or "bad" than need be, I'd love to hear suggestions for improvement! #include <iostream>
12
2169
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 code)? It's not a perfect analogy, but it seems to be a reasonable statement...
5
1729
by: Mohammad | last post by:
Hi, Is it possible to disable a method of a template class depending on the typename at compile time? thanks!
21
2113
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 doesn't seem to work. Here it is: #include <iostream> #include <cstdlib> using namespace std; template<int n>
1
2049
by: n.torrey.pines | last post by:
std::pair explicitly defines a default constructor. This makes it impossible to instantiate it with a type that does not have a default constructor (or it is private). I wonder if it would be possible to define std::pair in such a way (using template metaprogramming) that the default constructor is defined if and only if both of pair's argument types are default- constructible.
7
3589
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 metaprogramming is supported in C# (.NET)? For reference I found it: http://en.wikipedia.org/wiki/Template_metaprogramming. Thanks to all.
1
2397
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 producing high performance C++ code; code that is provably correct. The issue here is orthogonal to the question of expression templates, which at present seem to me to be relatively simple.
3
1860
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 Gurtovoy. Iím not doing this because I want to be a Meta Programming guru (because a lot of that stuff looks too crazy for use in the real world). Rather I want to learn heavyweight templates and this is the only
12
3380
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
0
9936
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9791
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11138
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10846
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10412
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7970
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7123
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.