Please Enter Your Search Term Below:
 Websearch   Directory   Dictionary   FactBook 
  Wikipedia: Generic programming

Wikipedia: Generic programming
Generic programming
From Wikipedia, the free encyclopedia.

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".

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

For example, in C++ code,

template 
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. Most languages can deduce the actual datatype when the template is used:

max(4, 10)  // implicit int

Anyway, it can also be explicit:

max(4.3, 2)
In the later example C++ requires the explicit datatype, since the first parameter type is different from the second, and the actual T would be ambiguous.

Uncommon, template metaprogramming is a way of making algorithms evaluate when your code is compiled.


See also Partial evaluation


  

From Wikipedia, the free encyclopedia. 
Modified by Geona