techhub.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A hub primarily for passionate technologists, but everyone is welcome

Administered by:

Server stats:

5.3K
active users

Jakub Neruda

Trying a new thing here - a bi-weekly , mainly aimed at coding in C++. Here's the first tip:

Concepts are a C++20 feature that greatly simplifies templated code and allows you to build powerful type trait restrictions.

For example, you can create a function that accepts a concrete type that implements a certain interface, allowing the compiler to optimize the virtual table away. Or you can define static interfaces where an object is required to have certain methods or even attributes, even if it doesn't implement any virtual interface. Or you can restrict the function to be called only with a small subset of well-known types.

Concepts do not replace dynamic polymorphism as you cannot do everything in compile-time. Still, it can open new optimization opportunities and help you write in-place construction functions like std::make_unique without an excessive amount of unreadable templates.

@jakub_neruda concepts looks really cool, thanks for the examples it is much more clear now!

@lexplt Glad to help! Follow the hashtag for more tips in the future 😉