Naming conventions for template types?

For C++ templates I have a couple of patterns

If there is just a single template parameter, I name it T (or U,V for nested templates).

When there are multiple parameters and the use is not immediately obvious then I use descriptive names prefixed with T. For example, TKey, TValue, TIdentifiier, etc … This makes the parameters fairly easy to spot throughout the template usage.

I would avoid the all upper case version though. Most people use all upper case identifiers in C/C++ to represent a macro definition. Repeating that pattern for a template parameter is likely to confuse people down the road.

Leave a Comment