24Additional Vocabulary Types

Vocabulary types are types that you are likely to use all the time, just as much as primitive types such as int and double. They are often used to build more complex types. Using vocabulary types makes your code safer, more efficient, and easier to write, read, and maintain. Examples of vocabulary types discussed earlier in this book are vector, optional, string, unique_ptr, shared_ptr, and so on.

This chapter starts the discussion with two additional vocabulary types: variant and any. It then continues with a more in-depth discussion of tuples, a generalization of pairs, and their operations. Next is monadic operation support for optionals, which makes chaining operations on optionals so much easier. This is because you won't have to verify whether an optional is empty before applying a next operation on it. The chapter finishes with a discussion of expected, which is a data type capable of storing either a value of an expected type or an error value. The type used to represent the error ...

Get Professional C++, 6th Edition 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.