All posts in "Templates"

Removing Duplicates in C++ CRTP Base Classes

Published August 28, 2018 - 3 Comments

At the beginning of the summer, we talked on Fluent C++ about 7 projects to get better at C++ during the summer. Reader Sergio Adán has taken up the challenge, and picked up Project #1 about how to avoid duplicates in a variadic CRTP. Today as summer is drawing to an end, Sergio shares with […]

How to Reduce the Code Bloat of a Variadic CRTP

Published July 3, 2018 - 3 Comments

In the previous post we’ve seen how to introduce variadic templates into the CRTP pattern, and how it allowed to create classes with various sets of opt-in features. For instance, the class X would have a basic interface but also augment them by inheriting from a set of CRTP base classes: template<template<typename> typename… Skills> class X […]

Variadic CRTP Packs: From Opt-in Skills to Opt-in Skillsets

Published June 26, 2018 - 2 Comments

Last week we’ve seen the technique of the variadic CRTP, that allowed to plug in generic extra features to a class. For instance, we’ve seen the following class X: template<template<typename> typename… Skills> class X : public Skills<X<Skills…>>… { public: void basicMethod(); }; X can accept extra features that plug into its template parameters: using X12 = […]

How to Turn a Hierarchy of Virtual Methods into a CRTP

Published May 22, 2018 - 5 Comments
virtual methods CRTP

After reading the series of posts on the CRTP, Fluent C++ reader Miguel Raggi reached out to me with the following email (reproduced with his permission): Dear Jonathan Boccara, […] After reading the posts on the curiously recurring template pattern, I’m wondering how to (expressively) implement this with 3 or more classes. Say, you have 3 […]