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:


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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.