C++ Traits Class

28 Jan 2013

In real world opensource C++ libraries, you often see traits class used in some template declarations. But what are they?

Basically it is a class used in place of template parameters. As a class, it aggregates useful types and constants; as a template, it provides an extra level of indirection to make template parameters parameterizable, plugin-able. And it is the birth of trait class that makes writing C++ templates much cleaner. It is a class to encapsulate ‘types’.

To read some original ideas of Traits, check out here. Warning! The article pointed by the link is really a good one!