Policy-Based Data Structures

about | archive

[ 2007-May-25 21:31 ]

One advantage to C++ templates is that they are generated at compile time, and thus can be written so that the code is as fast as if templates weren't used. As part of the GCC 4.2 release, the GNU C++ library now includes Policy-Based Data Structures. This is a library that allows the algorithms and policies used internally in the data structure to be specified via various template parameters. Coincidentally, I had effectively implemented a hash table in this fashion a few weeks ago, when I was testing the performance of various tweaks. While I think this is very cool, and the documentation is very interesting, I don't think the library is very useful. In most cases, the performance of the basic data structures do not matter. Only in the rare case where there is a hot spot in the application would a programmer ever want to use this library, and only when they were able to actually measure and compare the performance of the various options. Being able to do this by changing a template parameter would be useful in this situation, but otherwise I think it is a bit of overkill.