Generic Programming Without (Writing Your Own) Templates

By Tina Ulbrich

Generic programming is a technique where functions and data structures are defined as general as possible. The goal is that they work with different data types and therefore are reusable.

In C++ generic functions and data structures are typically realized by using templates.

Templates are a great tool for generic programming but they come with their own set of challenges. They can be hard to read/write and influence compile times negatively. And sometimes they are even too generic. C++20’s concepts can help with that but I want to show how you can be generic in your code without writing your own templates.

To do that, we will explore some C++17 and C++20 features from the standard library, like std::span, std::variant and std::any. I will explain what they are, where they are useful and how to use them.

I will also show some features you can find in other libraries, e.g. GSL.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.