Current Article  

Generic programming

In computer science, generics aretechnique that allows one valuetake different datatype (so-called polymorphism) asas certain contracts (so-called subtype)kept. The programming styleitcalled "generic programming".

Among OOP languages, C++, Beta, Eiffel, Ada,later versionsJava provides generic facility. In C++, templates support genericspopularizednotiongenerics.

For example,C++ code,

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

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

Uncommon, template metaprogramming iswaymaking algorithms evaluate when your codecompiled.


See also Partial evaluation


Copyright 2004. All rights reserved.