Templates and Metaprogramming

Recently I’ve begun to take over a club called Game Engine Architecture Club at DigiPen. The founder of the club graduated and asked me to try running it. I’ve found it be to a lot of fun! The first lecture I did was on template metaprogramming in C++ (TMP).

The lecture was recorded live and is currently up on DigiPen’s youtube channel for public viewing. Though the slides are visible during the video, I don’t think I can share the slides themselves publicly.

Hope you enjoy the video!

TwitterRedditFacebookShare

6 thoughts on “Templates and Metaprogramming

  1. MD

    Interesting presentation, thanks for sharing! :-)

    One note — expression templates (ETs) are not outdated, moving (in practice implemented as pointer(s) rebinding) is still more expensive than not moving — and is not applicable for all the use cases of ETs, see “C++11’s Move Semantics Are Not Free”: http://preney.ca/paul/archives/1009

    Move semantics and lambdas don’t completely replace ETs:
    http://stackoverflow.com/questions/11809052/expression-templates-and-c11
    http://stackoverflow.com/questions/10725299/understanding-the-benefits-of-move-semantics-vs-template-metaprogramming

    “Technically, you can do still better with expression templates, by delaying evaluation of the whole expression until assignment and adding all the matrices “in parallel,” making only one pass over the result. It would be interesting to know if there is a problem that has a truly optimal solution with rvalue references; one that can’t be improved upon by expression templates. ”
    // http://cpp-next.com/archive/2009/09/making-your-next-move/

    ETs are actually quite useful in gamedev, since they come in handy when implementing linear algebra routines efficiently:
    http://www.altdevblogaday.com/2012/01/23/abusing-c-with-expression-templates/
    http://en.wikipedia.org/wiki/Expression_templates
    http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template

    Eigen is a prime example:
    http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html
    http://eigen.tuxfamily.org/dox/TopicLazyEvaluation.html

    Another note — type traits with static_assert (and then also std::enable_if, but it’s less preferable) replace many use cases of SFINAE:
    http://en.cppreference.com/w/cpp/types
    http://en.cppreference.com/w/cpp/types/enable_if
    // Boost.TTI is also relevant here: http://www.boost.org/libs/tti/
    That being said, C++11 bring a pretty cool improvement, Expression SFINAE: http://stackoverflow.com/questions/12654067/what-is-expression-sfinae

    Reply
    1. Randy Gaul Post author

      Oh wow, thanks a lot for all the cool information! Yeah like I mentioned, I haven’t studied ETs much at all, so it makes sense there’s a lot more to be said about them. I’ll be checking out some of your links.

      Reply
  2. Andrea Bigagli

    Nice talk,

    but are you sure C++11 allows for function template partial specialization?

    I couldn’t have neither clang 3.3 nor gcc 4.8.1 get to compile one and I couldn’t find mention in to the standard.

     

    Andrea

    Reply
    1. Randy Gaul Post author

      I’m actually not sure at all. I don’t keep up very closely with upcoming features. I just recall seeing that somewhere as a planned feature.

      Reply
  3. Pingback: Performance em C++ | Vinipsmaker labs

Leave a Reply

Your email address will not be published. Required fields are marked *