3 ms·
It's certainly more than just templates, but it's also not the whole hairy c++ - it's C + templates, RAII, and namespaces. It's less template metaprogramming a
by verall 6y ago
It's certainly more than just templates, but it's also not the whole hairy c++ - it's C + templates, RAII, and namespaces.
It's less template metaprogramming and just templates to generate efficient code - stuff used to be done by abusing the proprocessor can now be handled by a (slightly) more elegant templating engine rather than a string pasting engine.
Classes are used for resource management/RAII, like we have a AQUIRE_MUTEX_IN_SCOPE() macro which will release mutex when scope is exited, this is supremely useful and generalized to many resources.
Lastly namespaces are huge. In big C codebases you have to be super pendantic about naming modules and APIs consistently because otherwise it becomes a nightmare.
C++ does get in the way still sometimes, like when you want to do something slightly dirty for perf reasons, say aliasing between structs. You first write it in a way that makes sense, basically how you would write it in C, but it's UB in C++, so you rewrite it with virtual calls or memcpys such that the compiler should be smart enough to arrive at the same result as C would have with the straightforward implementation. This works great until it doesn't, your last option is to try to solve it with templates, and that hole is very deep.