The Maw

Join the Ultimate Halo forum. Explore the inner depths of the Halo Megastructure, and realize your true potential as the savior of humanity
 
HomePortalGalleryFAQSearchRegisterMemberlistUsergroupsLog in

Share | 
 

  Templates

View previous topic View next topic Go down 
AuthorMessage
meodingu
Kig 'Yar
Kig 'Yar


Male
Number of posts : 141
Age : 31
Registration date : 2010-10-13

PostSubject: Templates    Tue Jan 11, 2011 8:58 am


Templates
See also: Template metaprogramming and Generic programming
C++ templates enable generic programming. C++ supports both function and class templates. Templates may be parameterized by types, compile-time constants, and other templates. C++ templates are implemented by instantiation at compile-time. To instantiate a template, compilers substitute specific arguments for a template's parameters to generate a concrete function or class instance. Some substitutions are not possible; these are eliminated by an overload resolution policy described by the phrase "Substitution failure is not an error" (SFINAE). Templates are a powerful tool that can be used for generic programming, template metaprogramming, and code optimization, but this power implies a cost. Template use may increase code size, since each template instantiation produces a copy of the template code: one for each set of template arguments. This is in contrast to run-time generics seen in other languages (e.g. Java) where at compile-time the type is erased and a single template body is preserved.
Templates are different from macros: while both of these compile-time language features enable conditional compilation, templates are not restricted to lexical substitution. Templates are aware of the semantics and type system of their companion language, as well as all compile-time type definitions, and can perform high-level operations including programmatic flow control based on evaluation of strictly type-checked parameters. Macros are capable of conditional control over compilation based on predetermined criteria, but cannot instantiate new types, recurse, or perform type evaluation and in effect are limited to pre-compilation text-substitution and text-inclusion/exclusion. In other words, macros can control compilation flow based on pre-defined symbols but cannot, unlike templates, independently instantiate new symbols. Templates are a tool for static polymorphism (see below) and generic programming.
In addition, templates are a compile time mechanism in C++ which is Turing-complete, meaning that any computation expressible by a computer program can be computed, in some form, by a template metaprogram prior to runtime.
In summary, a template is a compile-time parameterized function or class written without knowledge of the specific arguments used to instantiate it. After instantiation the resulting code is equivalent to code written specifically for the passed arguments. In this manner, templates provide a way to decouple generic, broadly applicable aspects of functions and classes (encoded in templates) from specific aspects (encoded in template parameters) without sacrificing performance due to abstraction.

hotel booking
transfer factor
Back to top Go down
View user profile
 
Templates
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Templates from Rhinos
» Characters --- Templates and Related Things (MUST READ)
» 40k Templates, tokens on a website
» Storm of magic templates
» Greenman Dseign Wrecked vehicle templates

Permissions in this forum:You cannot reply to topics in this forum
The Maw :: Off Topic :: General Discussion-
Jump to: