Working with heterogeneous values
The need to have a value that can hold different types of data at different times during the lifetime of a program is not new. C++ supports the union
construct of C, which essentially allows you to have a single type that can, at different times, assume values of different underlying POD types. POD or Plain Old Data types, roughly speaking, are types that do not require any special initialization, destruction, and copying steps and whose semantic equivalents may be created by copying their memory layouts byte for byte.
These restrictions mean that most C++ classes, including a majority of those from the Standard Library, can never be part of a union. Starting with C++11, these restrictions on a union have been ...
Get Learning Boost C++ Libraries 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.