Template specialization

suggest change

You can define implementation for specific instantiations of a template class/method.

For example if you have:

template <typename T>
T sqrt(T t) { /* Some generic implementation */ }

You can then write:

int sqrt<int>(int i) { /* Highly optimized integer implementation */ }

Then a user that writes sqrt(4.0) will get the generic implementation whereas sqrt(4) will get the specialized implementation.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents