Mittwoch, 5. Januar 2005

The difficulty of templates

Now that I have had some time to get used to the needs and habbits of templates and STL containers I feel like not everything is as nice as it seems to be from the far distance....

Well, to start at the beginning, let me explain what I have done.

At first I decided to re-write the Sniffnose CORE SDK. And how? Yes with C++ templates. The reason for this decision is simple: It's more generic and I am forced to think about the code in a quite more detailed way. So I took some pieces of the existing code and modified it accordingly.

This made me aware of a problem I never got in touch with this intensively - exporting templates from dynamic libraries. Have you ever tried to do this? If not, don't just even try - it doesn't work. Well, it works, but only If you are willing to specialize the template and export this class - but why should I export a specialized template? It's not better than a "normal" class - DAMN!

And today I found a second thing. OK, this was more due to the fact that I haven't used templates intensively so far - especially the STL containers. Using const values in these containers is something which is not advisable, BUT there are compilers the are willing to accept these constructs - for instance VC.NET 2003. The funny thing about this is, that VC6 complains - btw: in a very cryptic way - about std::set :)

Hope you find this information useful.