Loading…
CppCon 2018 has ended
View analytic
Tuesday, September 25 • 15:15 - 15:45
A Semi Compile/Run-time Map with (Nearly) Zero Overhead Lookup

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

An associative map container is one of the most useful data-structures in any modern program. Given a key, it can look-up the corresponding value incurring some runtime overhead. Often, however, this overhead is not strictly necessary as the key originated (either directly or indirectly) from a value which was known to the compiler at compile-time - such as a literal. In this talk, I will present a semi compile-/run-time map which can overcome this overhead by using C++’s constexpr features.

Yet another constexpr hash map talk, I hear you say? This one is different! Most constexpr maps presented at previous conferences are either constexpr-only, i.e. the values cannot be changed at runtime, or, require that all possible keys of the map are defined in one place making it unsuitable for library code. In contrast, the map presented in this talk, only calculates the storage of the key’s associated value at compile-time, but loading/storing the value and adding key/value pairs still occurs at run-time.

It will be shown how such a map can be used to implement a super efficient cache. In its most simplest form, looking up the storage of a primitive type for a given compile-time key has the same overhead as accessing a global variable. It will be shown that the underlying principle is surprisingly easy (3 lines of code) and the difficulty actually lies in associating any compile-time identifier to a unique C++ type - especially string literals. I will show how this can be achieved using constexpr if and constexpr lambda expressions - both C++17 features.

Speakers
avatar for Fabian Renn-Giles

Fabian Renn-Giles

Senior Software Engineer, Fielding DSP
Fabian Renn-Giles (PhD) is a freelance C++ programmer, entrepreneur and consultant in the audio software industry. Up until recently he was staff engineer at ROLI Ltd. and the lead maintainer/developer of the JUCE C++ framework (www.juce.com) - an audio framework used by thousands... Read More →


Tuesday September 25, 2018 15:15 - 15:45
Keystone (404)

Attendees (177)