FACTOID # 131: United we stand? The United Kingdom and United States are both in the top ten for Gross Domestic Product - and for child poverty.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Curiously Recurring Template Pattern

In software engineering, the curiously recurring template pattern (CRTP), is a software design pattern where a base class template is instantiated with a derived class type as its template parameter. The name of the pattern was coined by Coplien[1], who had observed it in some of the earliest C++ template code. Software engineering (SE) is the practice of creating and maintaining software applications by applying technologies and practices from engineering, computer science, project management, application domains and other fields. ... In software engineering, design patterns are standard solutions to common problems in software design. ... In computer science, generics is a technique that allows one value to take different datatypes (so-called polymorphism) as long as certain contracts such as subtypes and signature are kept. ... C++ (generally pronounced see plus plus) is a general-purpose programming language. ...


Example

 // The Curiously Recurring Template Pattern (CRTP) struct derived : base<derived> { // ... }; 

Typically, the base class template will take advantage of the fact that member function bodies are not instantiated until long after their declarations, and will use members of the derived class within its own member functions, via the use of a static_cast, e.g.:

 template <class Derived> struct base { void interface() { // ... static_cast<Derived*>(this)->implementation(); // ... } }; struct derived : base<derived> { void implementation(); }; 

This technique achieves a similar effect to the use of virtual functions, without the costs (and some flexibility) of dynamic polymorphism.


See also

  • Barton-Nackman Trick

Barton-Nackman is a programming trick in C++ invented by John Barton and Lee Nackman [1]. Originally, it provided a way to overload function templates when the C++ language did not support the feature. ...

References

  • Coplien, James O. (1995, February). "Curiously Recurring Template Patterns". C++ Report: 24–27.


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m