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

template meta programming

I am not sure if the question is relevant to this group.

Is there a proof that template metaprogramming is Turing-complete? Is
the proof trivial - just replace all the template instantiaion with a
function call and since function calls are turing complete, template
metaprogramming is turing complete. I am not sure if this is a valid
proof. I may not even make sense, as I am not very confident when it
comes to theoritical computer science.

However, my main question is - template metaprograms can work only on a
given input input which are know statically at compile time (Correct me
if I am wrong). While a general C++ program can work on any input. If
this is the case, how can we conclude that template metaprograms have
the same computational power as a general C++ program? For eg, I tried
to write a quicksort using template metaprograms, but in vain. The way
one partitions the input set is highly input dependent and even for a
given input, the partition changes across the levels of recursion. How
can we make use of template meta programming, in a case like this?

Ganesh

Oct 20 '05 #1
2 1639
Ganesh wrote:
I am not sure if the question is relevant to this group.

Is there a proof that template metaprogramming is Turing-complete? Is
the proof trivial - just replace all the template instantiaion with a
function call and since function calls are turing complete, template
metaprogramming is turing complete. I am not sure if this is a valid
proof. I may not even make sense, as I am not very confident when it
comes to theoritical computer science.
It is Turing complete (and of course there is a proof) but your proof
does not work because your reduction goes the wrong way. You need to
provide a general transformation from a Turing complete program to a
template metaprogram, not the other way around.

However, my main question is - template metaprograms can work only on a
given input input which are know statically at compile time (Correct me
if I am wrong). While a general C++ program can work on any input. If
this is the case, how can we conclude that template metaprograms have
the same computational power as a general C++ program? For eg, I tried
to write a quicksort using template metaprograms, but in vain. The way
one partitions the input set is highly input dependent and even for a
given input, the partition changes across the levels of recursion. How
can we make use of template meta programming, in a case like this?

Just because template metaprograms are Turing complete doesn't mean they
are convenient to use. You can indeed write quicksort in a metaprogram
but you'll have to somehow supply the "input" to quicksort at compile
time. That is, it must somehow be embedded in the program that you give
to the compiler.
Ganesh

Oct 20 '05 #2
Ganesh wrote:
I am not sure if the question is relevant to this group.

Is there a proof that template metaprogramming is Turing-complete? Is
the proof trivial - just replace all the template instantiaion with a
function call and since function calls are turing complete, template
metaprogramming is turing complete. I am not sure if this is a valid
proof. I may not even make sense, as I am not very confident when it
comes to theoritical computer science.


I think the simplest, most straight-forward way would be to implement a
turing machine in a template meta program. This shouldn't be too hard.
You have compile time multi-dimensional arrays, tmp lists, a tmp if-else
construct. In fact, after a google search, I just saw a paper by Todd
Veldhuizen doing the exact same thing. It requires some effort, but not
too much.

--
Regards,

Ferdi Smit (M.Sc.)
Email: Fe********@cwi.nl
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
Oct 20 '05 #3

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

Similar topics

4
by: Ingo Nolden | last post by:
Hi, I want to write a template class that holds another class that uses the same template. This recursion should stop after a predefined number. I think it's either impossible or easy, but I...
8
by: Tjerk Wolterink | last post by:
I have xml inpput like this: <meta:empty/> And xsl like this: <xsl:template match="meta:empty">A</xsl:template> <xsl:template match="//meta:*">B</xsl:template>
8
by: Jon Rea | last post by:
http://osl.iu.edu/~tveldhui/papers/Template-Metaprograms/meta-art.html Can anyone shed some light on the need for stuff like this when using any of the most modern compilers? If i have a...
5
by: Jon Rea | last post by:
I work with molecular simulations. In a normal infinate space simulation, a particle can occupy any cartesian position in space. If i want the distance between two particles in a system I can...
35
by: Steven T. Hatton | last post by:
Perhaps I'm just a bit frustrated, and I will soon realize the clear truth of the matter, but right now I have some serious misgivings about the value of investing a lot of time and effort into...
2
by: adrian.hawryluk | last post by:
Hi everyone, I've been using templates for a while, but I'm not at full power yet (knowledge=power) ;). Does anyone know where I can get information on this 'new' template usage? template<a...
7
by: Kevin | last post by:
I'm creating a template to support state machines. In doing so, I need to pass an enumeration for the number of transitions and a non type parameter for the range of the enum (to allow me to...
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...
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
0
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,...
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...

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.