I was reading one of the old Guru of the Week articles on typename, #35. At the very end, you can find the following snippet:
#include <iostream> using std::cout; using std::endl; struct Rose {}; struct A { typedef Rose rose; }; template<class T> struct B : T { typedef typename T::rose foo; }; template<class T> void smell( T ) { cout << "awful" << endl; } void smell( Rose ) { cout << "sweet" << endl; } int main() { smell( A::rose() ); smell( B<A>::foo() ); }
I don't get this. My first guess was that the second smell invocation led to the template smell being instantiated due to something you easily overlook (what should the joke be about, otherwise?!). But both calls lead to "sweet" being printed out. And isn't that to be expected, after all? In typedef Rose rose;, Rose is not a dependent name, so that's fine. In typedef typename T::rose foo;, rose is dependent, but typename mitigates that. My question(s):
- What's the point of this snippet? Am I missing a sense of humour here?
- The article is from 1998; were there any language changes that alter what this code does?
Here is a condensed version of the snippet on godbolt. I tested every compiler that looked old (e.g. gcc-4.4.1, but note that the above snippet is still 11 years older than gcc-4.4.1).