Item 54. Traits

Sometimes it’s not enough to know just an object’s type. Often, there is information related to the object’s type that is essential to working with the object. In Embedded Type Information [53, 189], we saw how complex types like the standard containers often embed information about themselves within themselves:

image

The process algorithm works well with our Seq container but fails with a standard vector container, because vector does not define the nested type names that process assumes are present.

We can process a ReadonlySeq container because it validates our assumptions, but we may also want to process containers that do not ...

Get C++ Common Knowledge: Essential Intermediate Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.