BIGpedia.com - Barton-Nackman - Encyclopedia and Dictionary Online
encyclopedia search

Barton-Nackman

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. Barton and Nackman took advantage of a process called "friend name injection", in which the C++ compiler used the type parameters of a class template to instantiate nontemplate friend functions of that class and then compiled them under normal rules of function overloading [2,3].

Today the Barton-Nackman trick has become synonymous with "curiously recurring templates" (a term due to Coplien [4], but which Barton and Nackman popularized), in which a base class template is instantiated with a derived class type as its template parameter. This is useful for compile-time optimization of polymorphic behavior. For example, a base class instance can be made to call a derived class member function without using the virtual function table , since the compiler can resolve the function call during compilation. For sample code, see Techniques for Scientific C++, Section 1.3.3.

See Also

Inheritance

Comparison of Generics to Templates

Template Metaprogramming


References

[1]

[2]

[3] Vandevoorde, David; Josuttis, Nicolai M. (2002). C++ Templates: The Complete Guide. Addison-Wesley Professional. ISBN 0201734842.

[4]

[5] "Techniques for Scientific C++." Techniques for Scientific C++. Accessed on April 12, 2005.




The contents of this article are licensed from Wikipedia.org under the GNU Free Documentation License.
How to see transparent copy

01-04-2007 01:21:04