Generic programming

This is an old revision of this page, as edited by TakuyaMurata (talk | contribs) at 04:50, 18 March 2003 (heavity rewriteing). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computer science, generics are a technique that allows one value to take different datatype (so-called polymorphism) as long as certain contracts (so-called subtype) are kept. The programming style with it is called "generic programming".

It is sometimes also called "template metaprogramming". Abstraction data

Among OOP languages, C++, Beta, Eiffel, Ada, and the latest Java provides generic facility. In C++, templates support generics and popularized the notion of generics.

For example, in C++ code,

template <int T>
T max (T x, T y)
{
  if (x < y)
    return y;
  else
    return x;
}

In this case, a pseudo-datatype T is called "subtype". T can be anything that can be compared.


See also Partial evaluation