Comment Re:STL downsides (Score 1) 1046
Solved easily by specialization. You should do something like:
template <class T>
list { /*...*/};
template <>
list <void*> { /* specialize for void* */ };
template <class T>
list<T*> : private list<void*> {
typedef list<void*> Base;
/* Forward all operations to Base */
};
Infact, Stroustrup talks extensively about this technique which he himself has applied a lot. In fact this technique can be applied to all classes which need to hold pointers. One more way to avoid code bloat is to place all operations that don't depend on templated type in a common base class and then derive your template class from this. This way you won't have multiple copies of functions, data members etc which don't depend on the template type.
template <class T>
list {
template <>
list <void*> {
template <class T>
list<T*> : private list<void*> {
typedef list<void*> Base;
};
Infact, Stroustrup talks extensively about this technique which he himself has applied a lot. In fact this technique can be applied to all classes which need to hold pointers. One more way to avoid code bloat is to place all operations that don't depend on templated type in a common base class and then derive your template class from this. This way you won't have multiple copies of functions, data members etc which don't depend on the template type.