473,695 Members | 2,483 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 1570


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
1250
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
2154
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
1721
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
2097
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
2041
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
3505
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
2383
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
1849
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
3346
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
0
8638
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
8578
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
9120
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...
0
8998
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8831
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
6494
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
5841
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
4345
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2278
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.