This rule is Obsolete | |
Synopsis: | The keyword typename shall be used to introduce a type parameter to a template |
Language: | C++ |
Severity Level: | 9 |
Category: | Style |
Description: |
A type parameter to a template can be introduced using either class or typename keyword. The latter is preferred, because the type does not necessarily have to be a class type, and the class keyword can therefor be confusing in this context. example: //>>==================================================================== template < typename ExceptionType // type of exception thrown , typename AssertionType // type of assertion expression > inline void BB_IB_MOD_Assert ( AssertionType assertion // this assertion will be checked , ExceptionType exception // this exception may be thrown ) // DESCRIPTION : Template function to check an arbitrary assertion // and to throw an appropriate exception if the check fails. // PRECONDITIONS : None. // POSTCONDITIONS : Assertion checked. // EXCEPTIONS : A user supplied object of ExceptionType is thrown // when the assertion fails. // NOTES : Calling this function, instead of writing out the // conditional throw statement directly, makes explicit that this // is an assertion of something that is supposed to be always true // and therefor not an ordinary part of the program logic. // See section 14.3.7.2 of "The C++ programming language, 3rd ed" // (Stroustrup) for more information on assert macro alternative. // Example: // BB_IB_MOD_Assert( // (CHECK_PRECONDITIONS && (item_ptr != nullptr)), // std::invalid_argument("item_ptr")); //<<==================================================================== { if (!assertion) { throw exception; } } |