473,854 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Template metaprogramming = interpretation

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...
Jul 22 '05 #1
12 2167
"Dave" <be***********@ yahoo.com> wrote...
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...


Every compiler is an interpreter if it can handle things like

int a = 1 + 2 + 3 + 4;

by creating a definition of 'a' initialised to 10 instead of
a special piece of code that performs three additions with the
immediate operands.

Victor
Jul 22 '05 #2

"Dave" <be***********@ yahoo.com> wrote in message news:vu******** ****@news.super news.com...
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...


I wouldn't agree with the statement. It's more of a supercompiler as it
can precompute code at compile time as opposed to translating language
at run time.

Jul 22 '05 #3

"Victor Bazarov" <v.********@com Acast.net> wrote in message news:u8%Fb.1190 86$8y1.371001@a ttbi_s52...
Every compiler is an interpreter if it can handle things like

int a = 1 + 2 + 3 + 4;

by creating a definition of 'a' initialised to 10 instead of
a special piece of code that performs three additions with the
immediate operands.


Every compiler has to be able to handle that. 1 + 2 + 3 + 4
is a constant expression.

The fact that a compiler can precompute things at compile
time makes it LESS of an interpreter than more of one in my
opinion.
Jul 22 '05 #4
Ron Natalie wrote:
"Dave" <be***********@ yahoo.com> wrote in message news:vu******** ****@news.super news.com...
Would people agree with the statement that to a large degree, using template
metaprogrammi ng 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...

I do see what you mean. You're getting the compiler to execute a
program for you, in much the same way that a Unix shell executes your
commands. However, the compiler is acting as a very special-purpose
interpreter, useful only for generating "traditiona l" code. The reason
is that run-time libraries, system interfaces, etc. are not available.

Ron Natalie wrote:
I wouldn't agree with the statement. It's more of a supercompiler as it
can precompute code at compile time as opposed to translating language
at run time.


I have to agree with Ron. The compiler is acting more like a CASE tool
than a traditional compiler. Speaking of which, whatever happened to
4GL's? Does C++ metaprogramming count?

-Jeff

Jul 22 '05 #5

"Jeff Schwab" <je******@comca st.net> wrote in message
news:G7******** ************@co mcast.com...
Ron Natalie wrote:
"Dave" <be***********@ yahoo.com> wrote in message news:vu******** ****@news.super news.com...
Would people agree with the statement that to a large degree, using templatemetaprogrammi ng techniques turns a C++ compiler into a C++ interpreter (butjust for the metaprogrammed portions of the code)? It's not a perfect
analogy, but it seems to be a reasonable statement...
I do see what you mean. You're getting the compiler to execute a
program for you, in much the same way that a Unix shell executes your
commands. However, the compiler is acting as a very special-purpose
interpreter, useful only for generating "traditiona l" code. The reason
is that run-time libraries, system interfaces, etc. are not available.

Yeah, this characterizatio n of template metaprogramming recently occurred to
me as I was trying my hand at a couple of miscellaneous problems just to see
if I could do it. I successfully implemented the compile-time calculation
of order statistics via template metaprogramming and it was at that point
the thought occurred to me that there is something sort of akin to
interpretation going on. Although, your point about the lack of
availability of any run-time libraries, etc... is well-taken!
Ron Natalie wrote:
I wouldn't agree with the statement. It's more of a supercompiler as

it can precompute code at compile time as opposed to translating language
at run time.


I have to agree with Ron. The compiler is acting more like a CASE tool
than a traditional compiler. Speaking of which, whatever happened to
4GL's? Does C++ metaprogramming count?

-Jeff

Jul 22 '05 #6
Dave wrote:
"Jeff Schwab" <je******@comca st.net> wrote in message
news:G7******** ************@co mcast.com...
Ron Natalie wrote:
"Dave" <be***********@ yahoo.com> wrote in message
just for the metaprogrammed portions of the code)? It's not a perfect
analogy, but it seems to be a reasonable statement...


I do see what you mean. You're getting the compiler to execute a
program for you, in much the same way that a Unix shell executes your
commands. However, the compiler is acting as a very special-purpose
interpreter , useful only for generating "traditiona l" code. The reason
is that run-time libraries, system interfaces, etc. are not available.

Yeah, this characterizatio n of template metaprogramming recently occurred to
me as I was trying my hand at a couple of miscellaneous problems just to see
if I could do it. I successfully implemented the compile-time calculation
of order statistics via template metaprogramming and it was at that point
the thought occurred to me that there is something sort of akin to
interpretation going on. Although, your point about the lack of
availability of any run-time libraries, etc... is well-taken!


So the question is - do you want metaprogramming in the regular language?

I've written a number of fancy templates and I find having to think in
this recursve "COME FROM" language a little bit of a challenge.

Then if you start to argue about this too much you'll have someone
remind you that lisp does all this in one language.

Jul 22 '05 #7

"Gianni Mariani" <gi*******@mari ani.ws> wrote in message
news:bs******** @dispatch.conce ntric.net...
Dave wrote:
"Jeff Schwab" <je******@comca st.net> wrote in message
news:G7******** ************@co mcast.com...
Ron Natalie wrote:

"Dave" <be***********@ yahoo.com> wrote in message
>just for the metaprogrammed portions of the code)? It's not a perfect
>analogy, but it seems to be a reasonable statement...

I do see what you mean. You're getting the compiler to execute a
program for you, in much the same way that a Unix shell executes your
commands. However, the compiler is acting as a very special-purpose
interpreter , useful only for generating "traditiona l" code. The reason
is that run-time libraries, system interfaces, etc. are not available.

Yeah, this characterizatio n of template metaprogramming recently

occurred to me as I was trying my hand at a couple of miscellaneous problems just to see if I could do it. I successfully implemented the compile-time calculation of order statistics via template metaprogramming and it was at that point the thought occurred to me that there is something sort of akin to
interpretation going on. Although, your point about the lack of
availability of any run-time libraries, etc... is well-taken!


So the question is - do you want metaprogramming in the regular language?

I've written a number of fancy templates and I find having to think in
this recursve "COME FROM" language a little bit of a challenge.

Then if you start to argue about this too much you'll have someone
remind you that lisp does all this in one language.


Yep, I agree with your sentiments! Not to mention that syntactically it's
awful. But that's not the fault of the language since templates weren't
envisioned to be used in this manner. Nonetheless, I find the concept of
compile-time programming (and especially that it is Turing-complete)
fascinating...
Jul 22 '05 #8
Gianni Mariani wrote:
So the question is - do you want metaprogramming in the regular language?

I've written a number of fancy templates and I find having to think in
this recursve "COME FROM" language a little bit of a challenge.

Then if you start to argue about this too much you'll have someone
remind you that lisp does all this in one language.


So do a number of other interpreted languages, including Perl and Tcl.
I think that's why template-based metaprogramming reminded the OP of an
interpreted language.

Jul 22 '05 #9
"Dave" <be***********@ yahoo.com> wrote in message
news:vu******** ****@news.super news.com...
Nonetheless, I find the concept of compile-time programming
(and especially that it is Turing-complete) fascinating...


Well I thought I followed alot of this thread, but what's 'Turing-complete'
?
Is there an incomplete?

--

Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Jul 22 '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>
5
1728
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
2109
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>
5
3374
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 list. I started by using a linked list of types with templates like: struct MyClass1 {}; struct MyClass2 {}; struct MyClass3 {}; struct NullType {};
7
3585
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
2394
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.
5
3625
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 anyone explain why loop unrolling doesn't play well with templates? Or better, can someone submit a code fragment to get desired results? Here are the command-lines I use to generate code: "g++ -DTEMPLATE=0 -o gotofun0 gotofun.cpp" works exactly as...
3
1859
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
3376
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
0
9899
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
11024
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
10740
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
10362
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...
0
7076
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
5738
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...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3182
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.