Template metaprogramming: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Alter: url, template type. URLs might have been internationalized/anonymized. Add: author pars. 1-1. Removed parameters. Some additions/deletions were actually parameter name changes. | You can use this bot yourself. Report bugs here. | Suggested by AManWithNoPlan | All pages linked from cached copy of User:AManWithNoPlan/sandbox3 | via #UCB_webform_linked 1782/2623
Corrected link to [Lisp (programming language)] that erroneously pointed to [Lisp] (the speech impediment)
Line 13:
Template metaprogramming is [[Turing-complete]], meaning that any computation expressible by a computer program can be computed, in some form, by a template metaprogram.<ref name=Veldhuizen2003>{{cite document|last1=Veldhuizen|first1=Todd L.|title=C++ Templates are Turing Complete|citeseerx=10.1.1.14.3670}}</ref>
 
Templates are different from ''[[Macro (computer science)#Programming macros|macros]]''. A macro is a piece of code that executes at compile time and either performs textual manipulation of code to-be compiled (e.g. [[C++]] macros) or manipulates the [[abstract syntax tree]] being produced by the compiler (e.g. [[Rust (programming language)|Rust]] or [[Lisp (programming language)|Lisp]] macros). Textual macros are notably more independent of the syntax of the language being manipulated, as they merely change the in-memory text of the source code right before compilation.
 
Template metaprograms have no [[Immutable object|mutable variables]]&mdash; 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 (computer science)|recursion]], as seen in the example below.