CppCon 2015 Program Highlights, 3 of N

The CppCon 2015 conference program has been posted for the upcoming September conference. We’ve received requests that the program continue to be posted in “bite-sized” posts, a few sessions at a time, to make the 100+ sessions easier to absorb, so here is another set of talks. This series of posts will conclude once the entire conference program has been posted in this way.

 

The C++ possess another language inside it: the template language. It is useful for a lot of things, from writting less code to compile time computations or checks, but can lengthen compile time too. To master it is not easy.

The following interrelated CppCon 2015 talks tackle these issues and more (part 1).

In this post:

  • Expression Templates - What, Why, When, Where
  • Visualizing Template Instantiations - Templator Demo
  • Variadic Templates - Guidelines, Examples and Compile-time computation
  • Variable Templates - C++14 compile-time computation
  • How I stopped worrying and love metaprogramming

 

Expression Templates - What, Why, When, Where - Part I, Part II, Part III

Expression Templates is one of this C++ idiom people learn to either love or hate. The main issues with ET is that everubody has its own conception about what they are, when they should be used, what benefits they give and what are their trade off. For a long time, Expression Tempaltes has been seen has a way to improve temporary heavy code. If the seminal implementation of ET by Todd Veldhuizen was actually about this, the landscape has changed since C++11 and C++14.

This workshop will go over : - what are exactly Expression Templates and what kind of use case they can solve elegantly and efficiently - what are the benefits that one may reap by using expression tempalte in its library - what are the real cost of expressont empaltes both at runtime and compile-time - which tools to use to not reinvent the tempalte wheel everytime including an introduction to Boost.PROTO an Boost.HANA.

The main objective is to clarify why, even in C++1*, this idiom has a meaningful set of applciations and how to navigate around its pitfalls.


Visualizing Template Instantiations - Templator Demo

Many C++ beginners shy away from employing templates in their code, because of the myth of templates being hard. Even seasoned C++ developers can have problems manually interpreting template code correctly as Olve Maudal's C++ pub quiz demonstrates. Overloads and template specializations make it hard for programmers and also IDEs to show a developer what happens without compiling a program and even with a compile one might not get, what actually happens unless an unintelligible error message from your compiler appears.

My students tried to alleviate that problem by visualizing template instantiation and overload selection in a C++ IDE and allow to navigate through template code in instantiation context that a compiler would only create internally and that is otherwise not available for humans. While still in its nascent state I hope to show what is possible and if things go as planned at the time of the submission you should be able to solve the template pub quiz questions without running the programs.


Variadic Templates - Guidelines, Examples and Compile-time computation

Writing class templates and functions accepting a variable number of arguments has been a burden before C++11. With variadic templates, both class templates with a variable number of arguments as well as functions can be formulated much easier and more type safe way.

Nevertheless, the authoring of variadic templates can be challenging for the uninitiated. Even the interpretation of variadic template code can be a problem, as Olve Maudal's famous pub quiz shows.

This session will build up understanding and the ability to use and author variadic template functions and variadic template classes from easy examples up to more complicated applications such as employing std::forward correctly, std::integer_sequence and other upcoming language features such as a template UDL operator that bridges the gap between string literals and std::integer_sequence.

Understanding pack expansion, sizeof... and other hard to get on first sight issues are my goal. In the end you should have seen guidelines that help you avoid the template instantiation trap from the pub quiz and correct usage of std::forward in your variadic templates.


Variable Templates - C++14 compile-time computation

C++11 introduced Variadic Templates, constexpr Functions and Literal Types that ease and allow type-safe computations at compile time. For embedded development this is an important aspect, because it provides a means to create ROMable data in type-safe C++.

In combination with C++14 mechanism of Variable Templates, that actually defines constants, and the relaxed constexpr function rules there are unprecedented possibilities for compile-time computations.

This talk does not only show the mechanisms available but also demonstrates non-trivial examples, how they can be used to compute interesting data at compile time.


How I stopped worrying and love metaprogramming

Horrible software engineering technique conceived in the forge of Hell or the Only True Way of doing C++ in 2015, template metaprogramming and its cohort of companion techniques are sure to create animation in a group of programmers.

What if we were to tell you that an actual software product, actually sold to real customers and in production for now several years has been built on it? What if we were to tell you that a lot of advanced template techniques helped us to build a better software faster?

This talk is all about real life examples of template metaprogramming, why they are useful and when and how you could use them in your own projects.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.