cpprussia C++ Russia 2019 (19.04.2019)

Compiler-friendly metaprogramming

img

Few advices how to write metaprograms minimizing stress of compiler.

Every developer plunging into the C++ world knows that templates are Turing complete, substitution failure is not an error, and in compile-time you can do amazing, sometimes even useful things. On the other side, an experienced C++ developer understands that "you can" does not mean "you should" and that there is a price for abusing metaprogramming. Compilation time is one of the most crucial bottlenecks, so we’ll discuss which operations/techniques are the most expensive for the compiler and how we can avoid them.

We’ll cover several issues, including:

  • why SFINAE is the last thing you should use;

  • why std::conditional_t is defined inefficiently;

  • what’s the difference between tuple implementations in Microsoft STL and libc++;

  • when you should use std::{conjunction,disjunction} and when — fold expressions;

  • why you shoudln’t use std::void_t;

  • how the concepts appearing in C++20 can help you.