I was reading the STL source code (which turned out to be both fun and very useful), and I came across this kind of thing
//file backwards/auto_ptr.h, but also found on many others.
template<typename _Tp>
class auto_ptr
//Question is about this:
template<>
class auto_ptr<void>
Is the template<> part added to avoid class duplication?
That’s specialization. For example:
This template would have
is_void<T>::valueasfalsefor any type, which is obviously incorrect. What you can do is use this syntax to say “I’m filling in T myself, and specializing”:Now
is_void<T>::valueisfalseexcept whenTisvoid. Then the compiler chooses the more specialized version, and we gettrue.So, in your case, it has a generic implementation of
auto_ptr. But that implementation has a problem withvoid. Specifically, it cannot be dereferenced, since it has no type associated with it.So what we can do is specialize the
voidvariant ofauto_ptrto remove those functions.