Curiously recurring template pattern: Difference between revisions

Content deleted Content added
inline references
Line 1:
The '''curiously recurring template pattern''' ('''CRTP''') is a [[C++]] idiom in which a class <code>X</code> derives from a class template instantiation using <code>X</code> itself as template argument. The name of this idiom was coined by [[Jim Coplien]]<ref>{{refcite journal | author=Coplien, James O. | title=Curiously Recurring Template Patterns | journal=C++ Report | year=1995, February | pages=24–27}}</ref>, who had observed it in some of the earliest [[C++]] template code.
 
== General form ==
Line 16:
</source>
 
Some use cases for this pattern are [[Template metaprogramming#Static_polymorphismStatic polymorphism|static polymorphism]], and other metaprogramming techniques such as those described by [[Andrei Alexandrescu{{ref|Alexandrescu}}]] in [[Modern C++ Design]] <ref>[[Andrei Alexandrescu]]: ''[[Modern C++ Design]]: Generic Programming and Design Patterns Applied'', Addison-Wesley, ISBN 3-8266-1347-3</ref>.
 
== Static polymorphism ==
Line 92:
==In other languages==
 
The CRTP makes an appearance in the [[Java language|Java programming language]] standard library where the [[Enumerated type|Enum]] class is defined as <code>Enum&lt;T extends Enum&lt;T&gt;&gt;</code>. Java programmers use the CRTP in practice when they write a comparable class: <code>class X implements Comparable&lt;X&gt;</code>.
 
==See also==
Line 99:
 
==References==
<references/>
* {{note|Coplien}}{{cite journal | author=Coplien, James O. | title=Curiously Recurring Template Patterns | journal=C++ Report | year=1995, February | pages=24–27}}
<!-- can somebody inline this reference in a relevant place?
* {{note|Alexandrescu}}[[Andrei Alexandrescu]]: ''[[Modern C++ Design]]: Generic Programming and Design Patterns Applied'', Addison-Wesley, ISBN 3-8266-1347-3
* {{note|Abrahams}}[[David Abrahams]], Aleksey Gurtovoy: ''C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond'', Addison-Wesley, ISBN 0-321-22725-5
-->
 
[[Category:Software design patterns]]