Traits are another common programming technique in conjunction with template programming. A traits class is a shadow class that accompanies another type and contains information associated with the other type.
The Standard C++ library has several examples of traits, such as character traits. The standard string class is a class template that is parameterized on the character type in order to allow for representation of tiny character and wide character strings. In principle, the string class template, named basic_string, can be instantiated on any character type, not just the two character types that are predefined by C++. If, for instance, someone needs to represent Japanese characters as a structure named Jchar, then the basic_string template can be used to create a string class for Japanese characters, namely basic_string<Jchar>.
Imagine implementing a string class template. You will need information that is not contained in the character type. For instance, you might want to calculate string length. You can do this by counting all characters in the string until you find the end-of-string character. How do you know which is the end-of-string character? It is '\0' for tiny characters of type char. There is also a corresponding end-of-string character defined for characters of type wchar_t, but how do you identify the end-of-string character for Japanese characters of type Jchar? Quite obviously, the information about the end-of-string character is associated with each character type, but it is not contained in the character type. This is exactly the purpose of traits: they provide information that is associated with a type, but is not contained in the type.
A traits type is a shadow type, typically a class template that can be instantiated or specialized for a group of types and provides information associated with each type. The character traits (i.e., see the char_traits class template in the Standard C++ library) contain a static character constant that designates the end-of-string character for the character type it is instantiated for.