Talk:Template metaprogramming

message: I don't know whether to be impressed or disgusted... supposedly it was the intention of the designers of C++ to eliminate the need for macros and tricky macro-based techniques.  But now it appears that when they introduced templates, they opened the door to a whole new avenue for creative, uh, hacking? 
Now that I have learned about this astonishing technique, I am going to try very hard to forget it. I think I'm going to go away now and write some programs in TECO. Dpbsmith 01:41, 9 Jan 2004 (UTC)
replies: text: As a counterweight to the opinion below (now above --MarSch) I have to say that I've never yet in any other language found another tool as powerful as templated metaprogramming. It has given me freedom to write incredibly terse and efficient code. Yes, it is difficult to get into, but then again, so is programming. It looks daunting, heck, it is daunting, but so are real-life powertools. Mikademus 18:27, 20 November 2005 (UTC)
replies: text: As a countercounterweight to what is said below. C++ template metaprogramming is a poor man's version of a number of language features found in a wide variety of languages such as macros in Lisp. It's daunting because it's accidental, not designed, so it lacks proper support (poor error reporting, inconsistency and non-orthogonality, poor compiler implementation and so on). The fact that it's daunting has little to do with its power which is no different from that of any other language with staged computation. Sigfpe 22:00, 21 July 2006 (UTC)
replies: text: Coincidentally I have just added a reference to a review which mentions template metaprogramming as poor Lisp macros and the nice quote. As it turns out Scheme > C++ --MarSch 19:26, 11 December 2006 (UTC)
thread_title:  Wow! or Eeeewwww! 

message: The book Metaprogramming GPUs with Sh actually doesn't have anything to do with template metaprogramming. The word in the title refers to run-time metaprogramming, as opposed to compile time metaprogramming. Sh is a runtime-embedded DSL in C++.
I'm not sure exactly what do with this. As one of the authors of that book, I can say that we're now avoiding the term metaprogramming more and more, because of this common confusion.
I'm leaving in the reference for now, but someone might want to either remove or clarify it.User:Sdt 
:I've removed it for now. --MarSch 19:28, 11 December 2006 (UTC)
thread_title:  MPSH book 

message: Eiffel, Haskell and ML are mentioned as a language supporting TMP.
How?
Eiffel: Bertrand Meyer's book (2nd ed, 1997) only mentions templates in connection
to C++, and manages to bad-mouth them fairly thoroughly in just one paragraph.
Meyer doesn't strike me as the kind of person who happily steals
successful ideas from C++, either ...
Haskell and ML: these support generic programming well,
but that's not the same thing as TMP, is it?
I see an external link to "Template Haskell". Following that link,
it's clear that this is not Haskell, but an extension to Haskell, i.e.
a different language.
JöG 17:25, 3 July 2007 (UTC)
thread_title:  Eiffel, Haskell, ML? 

message: In C++ macros are expanded by the preprocessor... I am not sure if this sentence is precise. Dpser 16:57, 27 September 2007 (UTC)
replies: text: It is precise. Preprocessing is just a stage of source code translation, according to the C++ Standard (see the [lex.phases] section). Enerjazzer (talk) 03:47, 29 November 2010 (UTC)
thread_title:  "A macro, which is also a compile-time language feature" 

message: This gets around the argument that template code can be arcane/hard to understand.  Basically multiple views of the same source code, and probably a nice learning tool.  —Preceding unsigned comment added by BrainRepair (talk • contribs) 12:31, 16 April 2008 (UTC)
thread_title:  Any Way to Expand Macros and Templates into code for source level debugging? 

message: I removed the statement that C# does allow template metaprogramming.  The person that added C# to the list also claims that Curl supports it.  This should be verified by a knowledgable person in this area. Edit Reference --80.152.5.244 (talk) 08:15, 12 June 2008 (UTC)
thread_title:  C# does not allow template metaprogramming 

message: I think the example given for "dynamic polymorphism" does not really match with what should be achieved by in static polymorphism and cannot really be replaced by it. The pattern that appears quite frequently in dynamic polymorphism (and can be replaced by static poly.) is the following: you have some clever algorithm which you put in the base class; this algorithm depends abstractly on some implementation in the derived class. So you make the implementation pure virtual in the base and fill in the implementation in the derived classes.
class Base
{
    virtual void implementation()=0; 
    public:
    virtual void clever_algorithm() { 
       ...
       implementation();
       ...
    }
};
class Derived : Base
{
    virtual void implementation(){
      // do whatever is appropriate in the derived class
    }
};
I think, this is more to the point. If nobody objects I would replace the code in the article by this code. (ezander) 134.169.77.186 (talk) 07:44, 30 September 2008 (UTC)
replies: text: There are many types of polymorphism, and the term "static polymorphism" is widely used. If you're limiting the meaning of polymorphism to only dynamic polymorphism, you're a minority then. The article is OK, no change is required. Enerjazzer (talk) 04:33, 29 November 2010 (UTC)
replies: text:  I agree. From a software-engineering standpoint, "static polymorphism" describes what is going on very well (and I'm sure I've seen it used this way elsewhere). You get almost all of the benefits of polymorphism in terms of code reuse and ability to decompose a problem into logical pieces. You give up the full dynamism but that is in exchange for runtime performance and runtime type safety. In terms of the type system, strictly speaking you can't say that a vector<double> is a vector, but in a very real sense a vector<double> is a Sequence (it models the Sequence concept); similarly it is a vector<T> in that a function declared template <typename T> void foo(vector<T>& x) would accept one. —Ben FrantzDale (talk) 14:58, 29 November 2010 (UTC)
thread_title:  Static polymorphism 

message: I have removed that "static tables" code example: http://en.wikipedia.org/w/index.php?title=Template_metaprogramming&action=historysubmit&diff=382683617&oldid=378332731 . It was relying on static initialization order of instantiated entities which is left unspecified on the Standard. There is nothing stopping the compiler from initializing "long ArcTanTab<INTTYPE,SHIFT,0>::K" *after* all those n's. If that happens, all those manual assignments to it are being overwritten by all-0 again when the program starts. 
It is also overall horrible and unexplained code (why was that "junk" char added - some explanation would be better)? If someone understand the matter, please fix and add it again. Static table generation, if done correctly, certainly are a good part of template metaprogramming. 87.154.137.171 (talk) 15:18, 3 September 2010 (UTC)
thread_title:  Removed terrible code example 

message: Hi, I was the one who had coded this part. In fact i was in a desperate need to develop static compile time tables. When i invented it (correct me if i am wrong, but internet then lacked any solution to do this). After i developed it i wanted to share it. However i never found the time to comment the same, and the example is not an example at all. Examples should be short and sweet. 
Good that you took it off the page, and left a comment for me/anyone else to see. 
Anyway if i find time again i will surely update it. BTW the junk character is a "static const" hence it makes the compiler assign a value to it at compile time. I could find no other way to force gcc to do it.  — Preceding unsigned comment added by 117.192.116.167 (talk) 19:55, 11 June 2011 (UTC)
thread_title:  Someone please correct this 

message: Would adding an external link to hamming-numbers.googlecode.com be useful? (Stroustrup found it a useful example of template metaprogramming). List of numbers are processed during compile time in order to calculate hamming numbers.
Dgutson (talk) 08:02, 25 September 2010 (UTC)
thread_title:  Hamming numbers example? 

message: Template metaprograms have no mutable variables— that is, no variable can change value once it has been initialized, therefore template metaprogramming can be seen as a form of functional programming. In fact many template implementations implement flow control only through recursion, as seen in the example below.
Template metaprograms can have mutable members. All the BOOST libraries use this concept and the member values can be changed.  — Preceding unsigned comment added by 117.228.51.106 (talk) 18:29, 31 December 2015 (UTC)
replies: text: Not generally, and a mutable variable wouldn't be template programming, it would be normal programming, or a combination; partial evaluation. It only becomes template progamming, if values are used to instantiate templates, and that can only be done with immutable values.Carewolf (talk) 03:21, 1 January 2016 (UTC)
thread_title:  The member of template class are mutable 

message: :) that must be explained somewhere - that's not metaprogramming? Thy, SvenAERTS (talk) 13:25, 6 July 2022 (UTC)
thread_title:  How to transfer a template from the english wikipedia to the french wikipedia?