Fluent C++ reader Sam wrote to me asking how to make a template expression simpler. This is an interesting question and I’m grateful to Sam for bringing it up. We’re going to examine this case where template parameters became unwieldy, and see how to simplify them by using template template parameters. The case Let’s have a […]
Defining a variadic pack of arguments of the same type turns out to be a deep topic as this is the fifth post and seventh technique we (I or guest writer Tobias in Part 4) discover on this topic. C++ variadic templates allow to define a parameters pack with any number of parameters of any […]
Among the many features that C++17 introduced, the standard library got std::conjunction and its brother (or is it a sister?) std::disjunction. std::conjunction allows to perform a logical AND on a variadic pack of boolean values, and std::disjunction a logical OR: std::conjunction<Bs…>::value // is true if all Bs… are true, false otherwise std::disjunction<Bs…>::value // is true if at least one […]
I originally wrote this post for Bartek’s blog. Here is a link to the original post. In C++, the normal way of passing a variadic pack of parameters is at the last position of the function: template<typename A, typename… Bs> void f(A&& a, Bs&&… bs) { // implementation of f… } But what if the […]
There is a compilation error that occurs often when writing template code that uses dependent types. If you know what’s going on, it is easy to fix it immediately. But if you don’t, you can spend a while staring a what looks like reasonable code, and wondering why the complier won’t have it. I’ve been […]
This is a guest post from Matthew Guidry. Matthew works as a software engineer in the CAD industry. He designs libraries and cross platform desktop applications, and is interested in using modern C++ techniques to improve overall software architecture. You can find Matthew online on Twitter @mguid2088. One of the usages of the CRTP is […]
This is a guest post by Tobias Loew. Tobias is programming now for over 35 years and started with C++ over 20 years ago. Got a PhD in maths and work for steag developing thermodynamic simulation tools (EBSILON). He likes to spend his spare time with his wife and their bunnies and writing code like […]
Today we have a guest post by Ádám Balázs. Ádám is a software engineer at Verizon Smart Communities Hungary developing video analytics for embedded systems. One of his passions is compile time optimizations so he immediately agreed to write a guest post on this topic. You can find Ádám online on LinkedIn. In the series […]
When you manipulate a collection of objects in C++–which is quite a common thing to do when programming in C++–STL algorithms are your loyal companions to perform operations with expressive code. But the STL algorithms, shipped in the standard library with C++, only apply to collections that are filled at runtime, during the execution of […]
We’re going further yet into the topic of how to make a variadic pack of template arguments of the same type. Indeed, since C++11 we can declare an arbitrary number of template parameters of any type: template<typename… Ts> void f(Ts&&… ts) { // … But we can’t declare an arbitrary number of template parameters of […]