Generic Programming in C++

C++ is a popular multi-paradigm programming language invented by Dr. Bjarne Stroustrup. Generic Programming achieved its first major success in C++ with the Standard Template Library, which has now become part of the ANSI/ISO C++ Standard. Since then, most generic libraries are written in C++.

C++ provides unique abilities to express the ideas of Generic Programming through templates. Templates provide a form of parametric polymorphism that allows the expression of generic algorithms and data structures. The instantiation mechanism of C++ templates insures that when a generic algorithm or data structure is used, a fully-optimized and specialized version will be created and tailored for that particular use, allowing generic algorithms to be as efficient as their non-generic counterparts. Additionally, the C++ notion of specialization allows compile-time selection among alternative algorithms. The flexibility of C++ templates has made C++ an attractive language for Generic Programming, Generative Programming, and Template Metaprogramming.

Although C++ can express most of the ideas of Generic Programming, doing so relies on careful documentation (see example concepts) and the use of certain C++ template techniques.