Debug Printing
Explore how C++17 enhances debug printing with features like if constexpr for compile-time code discarding, variable templates that simplify type traits, and fold expressions to streamline variadic template usage. This lesson helps you understand these tools to write cleaner, more efficient debug output.
We'll cover the following...
In this lesson we’ll examine a few more functions available in C++17. Do not worry about the code itself.
Here are all the functions and utilities you need to focus on:
if constexpr_vtemplateslinePrinter
Here you can see the following features:
• Line 5, 7, 11: if constexpr - to discard code at compile time, used to match the template
parameter.
• Line 5, 7, 11: _v variable templates for type traits - no need to write std::trait_name<T>::value.
• Line 20: Fold Expressions inside printWithInfo. This feature simplifies variadic templates. In
the example we invoke linePrinter() over all input arguments.
What we have seen here is just a small shadow of what’s to come ahead. See you in the next section!