Curiously Recurring Template Pattern
   HOME
*





Curiously Recurring Template Pattern
The curiously recurring template pattern (CRTP) is an idiom, originally in C++, in which a class X derives from a class template instantiation using X itself as a template argument. More generally it is known as F-bound polymorphism, and it is a form of ''F''-bounded quantification. History The technique was formalized in 1989 as "''F''-bounded quantification." The name "CRTP" was independently coined by Jim Coplien in 1995, who had observed it in some of the earliest C++ template code as well as in code examples that Timothy Budd created in his multiparadigm language Leda. It is sometimes called "Upside-Down Inheritance" due to the way it allows class hierarchies to be extended by substituting different base classes. The Microsoft Implementation of CRTP in Active Template Library (ATL) was independently discovered, also in 1995, by Jan Falkin, who accidentally derived a base class from a derived class. Christian Beaumont first saw Jan's code and initially thought it could not p ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Template (C++)
Template may refer to: Tools * Die (manufacturing), used to cut or shape material * Mold, in a molding process * Stencil, a pattern or overlay used in graphic arts (drawing, painting, etc.) and sewing to replicate letters, shapes or designs Computing * The main document from which mail merge documents are created * Style sheet (web development) or master page, a sheet or page on which a user can globally edit and format graphic elements and text common to each page of a document * Template (C++), a tool for generic programming in the C++ language * Template (file format), a standardized, non-executable file type used by computer software as a pre-formatted example on which to base other files, especially documents * Template (word processing), a standard document containing layout and styles used to configure word processing software * Template metaprogramming, a programming technique used by a compiler to generate temporary source code * Template method pattern, an object-orien ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Type Conversion
In computer science, type conversion, type casting, type coercion, and type juggling are different ways of changing an expression from one data type to another. An example would be the conversion of an integer value into a floating point value or its textual representation as a string, and vice versa. Type conversions can take advantage of certain features of type hierarchies or data representations. Two important aspects of a type conversion are whether it happens ''implicitly'' (automatically) or ''explicitly'', and whether the underlying data representation is converted from one representation into another, or a given representation is merely ''reinterpreted'' as the representation of another data type. In general, both primitive and compound data types can be converted. Each programming language has its own rules on how types can be converted. Languages with strong typing typically do little implicit conversion and discourage the reinterpretation of representations, whi ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Bounded Quantification
In type theory, bounded quantification (also bounded polymorphism or constrained genericity) refers to universal or existential quantifiers which are restricted ("bounded") to range only over the subtypes of a particular type. Bounded quantification is an interaction of parametric polymorphism with subtyping. Bounded quantification has traditionally been studied in the functional setting of System F<:, but is available in modern s supporting ( generics) such as



Barton–Nackman Trick
''Barton–Nackman trick'' is a term coined by the C++ standardization committee ( ISO/IEC JTC1/SC22 WG21) to refer to an idiom introduced by John Barton and Lee Nackman as ''restricted template expansion''. The idiom The idiom is characterized by an in-class friend function definition appearing in the base class template component of the curiously recurring template pattern (CRTP). // A class template to express an equality comparison interface. template class equal_comparable ; // Class value_type wants to have and !=, so it derives from // equal_comparable with itself as argument (which is the CRTP). class value_type : private equal_comparable ; When a class template like equal_comparable is instantiated, the in-class friend definitions produce ''nontemplate'' (and nonmember) functions (operator functions, in this case). At the time the idiom was introduced (1994), the C++ language did not define a partial ordering for overloaded function templates and, as a result, ove ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Method Chaining
Method chaining, also known as named parameter idiom, is a common syntax for invoking multiple method calls in object-oriented programming languages. Each method returns an object, allowing the calls to be chained together in a single statement without requiring variables to store the intermediate results. Rationale Local variable declarations are syntactic sugar. Method chaining eliminates an extra variable for each intermediate step. The developer is saved from the cognitive burden of naming the variable and keeping the variable in mind. Method chaining has been referred to as producing a "train wreck" due to the increase in the number of methods that come one after another in the same line that occurs as more methods are chained together. A similar syntax is method cascading, where after the method call the expression evaluates to the current object, not the return value of the method. Cascading can be implemented using method chaining by having the method return the ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


VTBL
In computer programming, a virtual method table (VMT), virtual function table, virtual call table, dispatch table, vtable, or vftable is a mechanism used in a programming language to support dynamic dispatch (or run-time method binding). Whenever a class defines a virtual function (or method), most compilers add a hidden member variable to the class that points to an array of pointers to (virtual) functions called the virtual method table. These pointers are used at runtime to invoke the appropriate function implementations, because at compile time it may not yet be known if the base function is to be called or a derived one implemented by a class that inherits from the base class. There are many different ways to implement such dynamic dispatch, but use of virtual method tables is especially common among C++ and related languages (such as D and C#). Languages that separate the programmatic interface of objects from the implementation, like Visual Basic and Delphi, also te ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Dynamic Polymorphism
In programming languages, name binding is the association of entities (data and/or code) with identifiers. An identifier bound to an object is said to reference that object. Machine languages have no built-in notion of identifiers, but name-object bindings as a service and notation for the programmer is implemented by programming languages. Binding is intimately connected with scoping, as scope determines which names bind to which objects – at which locations in the program code ( lexically) and in which one of the possible execution paths ( temporally). Use of an identifier in a context that establishes a binding for is called a binding (or defining) occurrence. In all other occurrences (e.g., in expressions, assignments, and subprogram calls), an identifier stands for what it is bound to; such occurrences are called applied occurrences. Binding time * ''Static binding'' (or ''early binding'') is name binding performed before the program is run. * ''Dynamic binding'' (or ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  




Virtual Function
In object-oriented programming, in languages such as C++, and Object Pascal, a virtual function or virtual method is an inheritable and overridable function or method for which dynamic dispatch is facilitated. This concept is an important part of the (runtime) polymorphism portion of object-oriented programming (OOP). In short, a virtual function defines a target function to be executed, but the target might not be known at compile time. Most programming languages, such as JavaScript, PHP and Python, treat all methods as virtual by default and do not provide a modifier to change this behavior. However, some languages provide modifiers to prevent methods from being overridden by derived classes (such as the ''final'' keyword in Java and PHP). Purpose The concept of the virtual function solves the following problem: In object-oriented programming, when a derived class inherits from a base class, an object of the derived class may be referred to via a pointer or reference of ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


Data, Context, And Interaction
Data, context, and interaction (DCI) is a paradigm used in computer software to program systems of communicating objects. Its goals are: * To improve the readability of object-oriented code by giving system behavior first-class status; * To cleanly separate code for rapidly changing system behavior (what a system ''does'') versus slowly changing domain knowledge (what a system ''is''), instead of combining both in one class interface; * To help software developers reason about system-level state and behavior instead of only object state and behavior; * To support an object style of thinking that is close to programmers' mental models, rather than the class style of thinking that overshadowed object thinking early in the history of object-oriented programming languages. The paradigm separates the domain model (data) from use cases (context) and Roles that objects play (interaction). DCI is complementary to model–view–controller (MVC). MVC as a pattern language is still used to sep ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  


F-bounded Quantification
In type theory, bounded quantification (also bounded polymorphism or constrained genericity) refers to universal or existential quantifiers which are restricted ("bounded") to range only over the subtypes of a particular type. Bounded quantification is an interaction of parametric polymorphism with subtyping. Bounded quantification has traditionally been studied in the functional setting of System F<:, but is available in modern s supporting ( generics) such as

Modern C++ Design
''Modern C++ Design: Generic Programming and Design Patterns Applied'' is a book written by Andrei Alexandrescu, published in 2001 by Addison-Wesley. It has been regarded as "one of the most important C++ books" by Scott Meyers. The book makes use of and explores a C++ programming technique called template metaprogramming. While Alexandrescu didn't invent the technique, he has popularized it among programmers. His book contains solutions to practical problems which C++ programmers may face. Several phrases from the book are now used within the C++ community as generic terms: ''modern C++'' (as opposed to C/C++ style), policy-based design and typelist. All of the code described in the book is freely available in his library Loki. The book has been republished and translated into several languages since 2001. Policy-based design Policy-based design, also known as policy-based class design or policy-based programming, is the term used in ''Modern C++ Design'' for a design appro ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]  




Andrei Alexandrescu
Andrei Alexandrescu (born 1969) is a Romanian-American C++ and D language programmer and author. He is particularly known for his pioneering work on policy-based design implemented via template metaprogramming. These ideas are articulated in his book ''Modern C++ Design'' and were first implemented in his programming library, Loki. He also implemented the " move constructors" concept in his MOJO library. He contributed to the ''C/C++ Users Journal'' under the byline "Generic". Alexandrescu worked as a research scientist at Facebook, before departing the company in August 2015 in order to focus on developing the D programming language. He became an American citizen in August 2014. Education and career Alexandrescu received a B.S. degree in Electrical Engineering from Polytechnic University of Bucharest (''Universitatea Politehnica din București'') in July 1994. His first article was published in the ''C/C++ Users Journal'' in September 1998. He was a program manager for Ne ...
[...More Info...]      
[...Related Items...]     OR:     [Wikipedia]   [Google]   [Baidu]