Alex Rivera | Logout

Naming conventions for template types?

Asked 2009-03-28T13:17:23.710
38

Traditionally, the names of template types are just a single upper-case letter:

template<class A, class B, class C>
class Foo {}; 

But I hesitate to do this because it's non-descriptive and hard therefore to read. So, wouldn't something like this be better:

template<class AtomT, class BioT, class ChemT>
class Foo {}; 

I also tend to think the following would not be a bad idea:

template<class ATOM, class BIO, class CHEM>
class Foo {}; 

It makes them stand out (and also, it's upper-case letters again). What's your opinion?

Edit
Report

1 Answer

1

If I have a class with one type parameter, I will use the name T. Also, it means that all operations in this class are working with T.

If I have a few parameters, I will name them as in your example, AtomT, BioT, etc.
If a template parameter is not a type of object with which we are working in class, e.g., strategy, comparator, or functor, I will use a name without T, e.g., ThreadStrategy, Compare.

Sometimes to avoid mixing styles, I will make typedefs in the class:
typedef T value_type;

--
The Boost naming conventions have this to say about template parameters:

Template parameter names begin with an uppercase letter.

answered 2009-03-28T13:27:17.507

Your Answer