A trait in C++ encapsulates a family of operations that allow an Algorithm or Data Structure to operator with that type with which it is instantiated. char_traits
are an example for grouping string
- and file-required functions.
But not all traits have "trait" in their name, right? numeric_limits
comes to mind. Is this a "Trait", too? Even without the name "trait" in it?
So, are there other Templates that could/should be considered a "Trait"? Besides the examples I found:
allocator_traits
how to get memorypointer_traits
how to access an object indirectlytype_traits
meta programmingchar_taits
for sequence of symbolsiterator_traits
how to get forward, backward and to the elementregex_traits
for... regexes.
I guess, what I am asking, too, is there a pure definition for traits?
Some things I am especially unsure about are:
numeric_limits
mentioned above<chrono>
s customization "traits", [20.11.4], i.e.duration_values
- what about Hashing? Can the functor
hash<>
be considered to be a trait? - If thats the case, are not all requirements "traits", like "CopyAssignable", etc?
- And then, are the abandoned "Concepts" the ultimate "trait"-Definition?
Update: The question what exactly makes a trait a trait seems a bit controversy in the details. Maybe a another question could be answered: Is there a comprehensive list which of the trait-like classes are new to C++0x, and which ones have already been in C++03? Maybe someone knows of a link to somewhere?