Thoughts from a C++ library developer.

C++17 is going to add std::variant.
To quote the linked documentation, it is a “type-safe union”.
A union is like a struct, but can only store one member at a time.
This has many applications, but sadly it doesn’t mix well with non-trivial types,
you have to call the destructor yourself etc.
Furthermore, nothing prevents you from accessing a union member that isn’t active.

std::variant fixes that. It correctly calls the destructor when switching the active member,
it prevents invalid access, etc.
However, I’m not quite happy with it and I needed an implementation now.
So I’ve decided to implement my own variant as part of my type_safe library.

It was a fun challenge and since my previous attempt was two years ago,
I could improve it a lot.
Let’s go through some of my design decisions.

Consider that you have a function template that takes a parameter on type T.
If the function template has a rather generic name like operator==, is a constructor,
or anything whose existence might be queried with type traits to further constrain other functions,
it is often beneficial if you can conditionally disable the function if the type does not have some required properties.
Otherwise the function will be “greedy” and accept more than it should - making some traits near useless,
as they only check for existence and the error only occurs later.

Conditionally removing functions if their template parameters don’t fulfill certain properties
is done with SFINAE.
But what if you have member functions of a class template that are not templates themselves?

C++11 introduced std::initializer_list.
This is a small class used if you want to initialize some container type with a pre-defined set of elements.
It allows very convenient syntax just like plain old C arrays have.

Yet it has a couple of problems.
This post will talk about them and how they can be fixed.

After two bugfix release for the parsing code, I finally got around to implement more features for standardese.
A complete refactoring of the internal code allowed me to implement some advanced features:
standardese now comes with member groups,
the ability to show inline documentation, a template language and many minor things that just improve the overall documentation generation.

If you’ve been a long reader of my blog, you might remember my memory library.
I haven’t forgotten about it, even though the 0.5 release was in February!
After three patches and a long pause in development to focus on standardese,
I’ve finally finished the 0.6 release.
It mainly provides two major features: composition and joint allocators.