O'Reilly logo

Beyond the C++ Standard Library: An Introduction to Boost by Björn Karlsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Library 7. Variant

How Does the Variant Library Improve Your Programs?

• Typesafe storage and retrieval of a user-specified set of types

• A means to store heterogeneous types in Standard Library containers

• Compile-time checked visitation of variants

• Efficient, stack-based storage for variants

The Variant library focuses on typesafe storage and retrieval of a bounded set of types—that is, on discriminated unions. The Boost.Variant library has many features in common with Boost.Any, but there are different tradeoffs as well as differences in functionality. The need for discriminated unions (variant types) is very common in everyday programming. One typical solution while retaining type safety is to use abstract base classes, but that's not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required