Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

How to specialize a function template correctly?


I have stumbled upon different ways to declare a function template
specialization.

Are the following examples synonymous or are there significant differences:

template<typename T>      // Primary function template
void myTemp(T) {

}

template<>                // int version with arg 'a'
void myTemp(int a) {
        // do something with a

}

template<>                // int type only version
void myTemp(int) {

}

template<>                // int int type version
void myTemp<int>(int) {

This happens with every function parameter. If you are not going to use
it in the function implementation, you can omit the name of the
parameter, leaving only the type. It's also common practice in order to
avoid warnings referring to the unused variable "a" (if you don't use
it, of course :)).

> template<>          // int int type version
> void myTemp<int>(int) {

> }

This is an explicit specialization, while the previous ones are
implicit. The point here is that, as every time in which you can deduce
the template parameters from the function arguments, you don't need to
write them explicitly.

If I can give you a suggestion, a lot of the things that you're asking
are covered in much more extent and accuracy in the chapter 13.5 of the
Stroustrup.

Regards,

Zeppe

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc