Crosstips.org

My fun Crossword solver project. Crosstips.org & Krysstips.se

Kung Fu

Fujian White Crane Kung Fu

Fry-IT

Fry-IT is the company I work for

Photos

Photoalbum, both old and new.

Zope

What I have and am doing with Zope

Receptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact me

My contact details and how to contact me.

 

KungFuPeople.com
Do you train Kung Fu?
Or know someone who does?
Then check out KungFuPeople.com


Mobile version of this page Mobile version of this page


 

C++ templates or not

http://www.mozilla.org/hacking/portable-cpp.html#dont_use_templates

c++, portability, mozilla, templates, compilers, casting

18th of February 2004

The Mozilla C++ portability guide says that developers should not use templates in their C++ code. Damn! I just learnt how to use templates in my Object Oriented Programming in C++ course. They are so useful that I can't understand why the compilers can't support it.

"Don't use the C++ template feature. This feature is still not implemented by all compilers, and even when it is implemented, there is great variation. Most of the interesting things that you would want to do with templates (type safe container classes, etc.) can be implemented with macros and casting, even though you do lose the type safety (pity). Often times subclassing can easily achieve the same result."

Without templates you have to write one function for every type:

 void swap(int & x, int & y) 
     int tmp = x; x = y; y = tmp;
 void swap(long & x, long & y) 
     long tmp = x; x = y; y = tmp;

And with templates you can generalise it like this:

 template <typename T>
 void swap(T & x, T & y) 
     T tmp = x; x = y; y = tmp;



Comment

 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.