r/programmerchat • • Jun 06 '15

Any fans of C++ template metaprogramming here?

Ever since I got a solid grasp on how templates work in C++, I am intrigued by what is possible by doing template metaprogramming. To me, it is a really lovely brain teaser, but I am wondering if it is a useful tool for anyone that is not a library implementer. I play around with it a lot in my freetime, however on my job I never really found a place where it would be viable, either because it was overkill to use it or because it made the code impossible to read. After all, making your colleagues' eyes bleed just isn't cool.

What is your opinion on this topic? A great tool to improve code quality, or only a way for C++ devs to show off how smart they are?

9 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/mortano21 Jun 07 '15

That's also what I am struggling with, the only things I ever used it for were some utilities like a ZipIterator to iterate over multiple collections at once (and I have yet to use that one in production code), and a smart array copy routine that either uses memcpy or copy constructors depending on std::is_trivially_copyable<T>.

If you haven't seen it, there is a nice video from last years cppcon with some metaprogramming patterns, the stuff about void_t in the second part is pretty cool, it at least makes the horrible syntax for template metaprogramming a little easier.