Rui said:
It appears that all tutorials I've read on templates state that the use of the keywords typename and class to specify the template parameter, stating that both expressions have exactly the same meaning.
That seems to be a bit strange. Is that true?
When it comes to declaring template parameters, the keyword 'typename'
does indeed have exactly the same meaning as keyword 'class'. There's no
difference whatsoever.
If so, what is the purpose of adding perfectly redundant keywords to a language?
Well, there's really no "adding" here. The keyword 'typename' has other
meaning in C++, when it is used in different context - it is used to
qualify dependent nested type names in declarations. The keyword
'class', as you no doubt know, also has a different meaning when used in
different context - it is used to declare class types. So, basically,
you can think of it that way: instead of introducing a new keyword for
template parameter declaration, the language borrowed an existing one -
'class', - and while it was at it, it decided that borrowing one more -
'typename' - will do no harm. So it did.
Even though they mean the same thing, you are free to develop your own
usage standard governing the selection of a specific keyword in each
specific case (like "use 'class' when a class type is expected, use
'typename' in all other cases"), which might improve the readability of
the code. Or not.