Why is boost :: ptr_list using the base void *?

The documentation for boost ptr_list claims that the container uses the base std::list<void*> .

Why do they use this type instead of the more specialized std::list<T*> ?

+7
source share
2 answers

Perhaps this will reduce the number of template instances. If it uses std::list<T*> then any use of ptr_list<T> will also create an instance of std::list<T*> . These are many instances if you use ptr_list .

+8
source

This makes it easy to share almost all of the code, regardless of the type (s) by which you create it. Almost all of the code is in a single std::list<void *> . Each instance only adds code for casting between T * and void * where necessary.

Of course, modern compilers / linkers can do a lot of this without such help, but this has not always been the case (and some people still use the old tool chains for various reasons).

+3
source

All Articles