August 2004
Intermediate to advanced
352 pages
7h 38m
English
Difficulty: 4
If you want to declare a function template specialization as a friend, how do you do it? According to the C++ standard, you can choose either of two legal syntaxes. According to real-world compilers, however, one of the syntaxes is widely unsupported; the other works on all current versions of popular compilers… except one.
Let's say we have a function template that does SomethingPrivate to the objects it operates on. In particular, consider the boost::checked_delete function template from [Boost], which deletes the object it's given—among other things, it invokes the object's destructor:
namespace boost {
template<typename T> void checked_delete(T* x) {
// … other stuff …
delete x;
}
}
Now, say you ...