C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A draft for modern switch - perfect hashing

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Fri, 23 May 2025 23:14:51 +0200
How about a templated class for perfect hashing instead: Something like a customizable string enumeration. You parametrize the class with the possible values. The class has member functions for reading or for hashing string values with and without guarantee/check that it is one of the predefined values. It also has the reverse function of returning the string for a hash. The class can create a hash value even during compile-time. Then it can be used for the existing switch case or for parsing.

Received on 2025-05-23 21:22:30