C++11 and algebraic types

As C++11 took shape, there was growing recognition that another area ripe for vocabularization was that of the so-called algebraic data types. Algebraic types arise naturally in the functional-programming paradigm. The essential idea is to think about the domain of a type--that is, the set of all possible values of that type. To keep things simple, you might want to think about C++ enum types, because it's easy to talk about the number of different values that an object of enum type might assume at one time or another:

    enum class Color {      RED = 1,      BLACK = 2,    };    enum class Size {      SMALL = 1,      MEDIUM = 2,      LARGE = 3,    };

Given the types Color and Size, can you create a data type whose instances might assume any of 2

Get Mastering the C++17 STL now with O’Reilly online learning.

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