Modeling Recursive Sum Types in C++11 Using boost::variant

It's been a while. But here's something cool.

I used to love pattern matching with sum types in OCaml in college. But I also
love how useful and ubiquitous C++ is. So I wanted pattern matching
and sum types, but in C++. Well, people say boost::variant can be
used as a sum type. The library boost::variant is fairly ubiquitous,
well-maintained, and can even run on C++98, the older C++ standard. I
can see how discriminated unions can implement “flat” sum types,
but can it be used to implement recursive
sum types?

Well, I decided to try it. It turns out, with a bit of scaffolding
on my part, I was able to implement a recursive sum type. I tried to
model the quintessential recursive type, the natural number, which is
either zero or the successor to some other number. The following code shows the results of
my efforts.