The way c++ template argument deduction works, both arguments are used
to deduce the template type in the three-argument overload of
mapOptional. This is a problem if the types are slightly different, even
if they are implicitly convertible. This is fairly easy to trigger with
integral types, as the default type of most integral constants is int,
which then requires casting the constant to the type of the other
argument.
This fixes that by telling the compiler to not use the default value for
argument deduction. The "telling" is done by spelling out the argument
type in a more complicated manner, as deduction only happens for simple
types. This allows the default value to be any type which is implicitly
convertible to the value type.
What if you just say
This way it's basically self-documenting and doesn't require enable_if magic.