473,781 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1661
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
2222
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 have no idea right now :-( A simplified version is here: template< unsigned Depth > class Foo
8
1378
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
2284
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 function : double Square( double d ) { return d * d;
5
1853
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 use: Maths::dvector va, vb; // Code here: Do something to initialise variables and move them around... double distance = dist(va,vb); I am currently looking at 'Periodic boundary simulations'. By this i
35
1930
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 template programming. I just finished reading the first 12 chapters of _C++ Templates: The Complete Guide_. One thing that struck me as I read these chapters is how much I didn't know about C++. I _know_ the core language specification is...
2
2008
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 (b, c, d)> Does one define it like:
7
7978
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 allocate an array of pointers big enough to hold one entry for each transition). My template declaration looks roughly like this: template <class TRANSITION, int NUMTRANSITIONS> class StateMachine { ***SNIP*** void RegisterTransition(TRANSITION...
3
1854
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
2
6647
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
9474
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
10306
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
10139
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...
1
10075
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
9931
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
6727
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
5373
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...
1
4037
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
2869
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.