Tutorial: Emulating strong/opaque typedefs in C++
Last week, I’ve released my type_safe library. I described it’s features in the corresponding blog post but because the blog post got rather long, I couldn’t cover one feature: strong typedefs.
Strong or opaque typedefs are a very powerful feature if you want to prevent errors with the type system – and as I’ve been advocating for, you want that. Unlike “normal” typedefs, they are a true type definition: they create a new type and allow stuff like overloading on them and/or prevent implicit conversions.
Sadly, C++ doesn’t provide a native way to create them, so you have to resort to a library based emulation.
» read more »BTW, type_safe received a couple of requested features: There are improvements to the monadic optional functions (
bind()
,map()
,unwrap()
as well as a newtransform()
), multi-visitation of optionals andArithmeticPolicy
to control over/underflow behavior of thets::integer<T>
.