In general I like templates.... but that example is just twisted....<p>Handle errors appropriately, don't wrap a C API like that for gods sake, thats just wasted code trying to be clever.<p>In 5 years time, someone will look at that and have to try and figure out what the <i></i><i></i> you were trying to do.
I am absolutely unconvinced by the added value of wrapping the C functions. Using TMP would be useful to adapt the C functions to a different interface, but from my understanding all it does is catching the error.<p>Additionally, the author implements count in the worst way possible, it's highly inefficient and it will result in very long compilation time. You don't need to do tail recursion, you can just write:<p>template <class... T>
using count = std::integral_constant<std::size_t, sizeof...(T)>;<p>Such errors make me uncomfortable as it seems the author isn't up to date on the topic. A+ for intent though.
I think templates get a bad reputation because in practice many uses of templates are not appropriate.<p>Too many clever people saw 3 repetitions of a pattern and decided to show case every template trick to create a "generic library" that is compile-time optimized, usually to solve a problem that doesn't exist.<p>Multiply that many times through the course of a project and you end up with code that seems to try to maximizes job security.
Implementing generics was a good idea. However, templates were not. They should have been dismissed as a bad job years ago, and replaced by a better metaprogramming facility with less complexity, if at all possible (given the complexity of C++, it may not be). Kind of like what Rust did, by pretty much just stealing syntax-rules wholesale from Scheme.