Attending this event?
View analytic
Tuesday, September 25 • 15:50 - 16:20
Making printf-style Logging a Little Easier With C++17

Sign up or log in to save this to your schedule and see who's attending!

Many people do development on systems that use printf-style logging. In order to do so, traditionally they have to do without the big benefit of C++ streams; namely, that objects know how to print themselves.

It is particularly tricky to keep format specifiers in sync with different types of integers, especially as people try to future-proof their code. Besides the integral types (from bool to long long) there are also the typedefs provided such as size_t, uint8_t, int16_t, etc., which have their own special macros. And then there are the signed versions of most of those types. It is very error-prone to keep these in sync, and bugs due to incompatible output range from embarrassing to costly.

To deal with this, we will develop an efficient, non-allocating string-like extensible class template which abstracts away the input type so the caller need not know or care what type of integer is being passed in. The class template will use many modern C++ features and techniques, including some from C++17, such as type traits, type lists, constexpr, deduction guides, variadic templates, const r-value references (!), etc.

While this class template is certainly useable out of the box, the more interesting part is in presenting the various design decisions and efficiency ramifications that went into developing it.


Nevin Liber

Senior Software Engineer, Ocient
He started programming in C++ over three decades ago, when a friend called and asked him what he knew about C++, which inspired him to learn all he could about the language. And he's still learning about it! Besides making a career out of it, he has been on the C++ Standards Committee... Read More →

Tuesday September 25, 2018 15:50 - 16:20
  • Level Beginner, Intermediate
  • Tags I/O, printf

Attendees (34)