Instantialization

Instantialization in generic programming is the process of assigning a static type to a generic template class at instantiation time.

Differentiating between Instantialization and Instantiation

Instantiation refers to the process of creating an instance of a class definition, this term is only applicable to classes. Instantialization differs in that it refers to the process of creating a strongly typed instance of a template definition. This template definition does not necessarily have to be of a class. Template definitions in C++ can also be created for functions. Since we cannot create an instance of a function (that wouldn't make sense), we instead instantialize a template function with a strong type so that we may invoke the function for that specific type. In C++ and possibly other languages, explicit function instantialization is not always required. If the instantialization type can be inferred by the compiler then the instantialization will be implicit. An erroneous example follows:

template<class T>
void anotherfunc(T a0, T a1)
{
   /* class contents */
}
int i0;
long l0;
anotherfunc(i0, l0); // this will generate a compile error
anotherfunc(i0, i0); // the compiler will translate this to anotherfunc<int>(i0, i0);

Example

"template classes are Not Real classes until they are instantiated for some type, at the point of instantialization"

template<class T> 
class List 
{ 
   /* class contents */ 
};
template<class T>
T somefunc(int i)
{
   /* class contents */ 
}

In C++ the class List represents a template class. List on its own is not a real class, that is, it cannot be instantiated until it is first instantialized. somefunc is a single template function that must first be instantialized before it is used. Calling somefunc without instantialization can result in a compile time error if the compiler is unable in infer the instantialization type properly.

List ambiguous_list; //this will not compile as it has not be instantialized
List<int> integer_list; //instantialization occurs once we specify the strong type between the right angle brackets.

Because of the nature of C++, instantialization and instantiation occur at roughly the same time (one after the other) in the above example. However, since functions cannot be instantiated, instantialization and invocation occur at roughly the same time (one after the other).