A set of hashing utilities for C++.
- Compile time friendly.
- Concise concept contrained API.
- Builds upon the basis of std::hash.
- Utilties to make hashing user defined types by composition easier.
- Support hashing for all cvref types.
tprt::hash is a free function which wraps the construction of the std::hash object in addition to providing the native ability to combine hash values. The hash implementations for fundamental types have been replaced to be compile time friendly.
static constexpr auto h = tprt::hash(42, 4.2f, 't', 'p', 'r', 't');
Perhaps one of the most useful utilities is hash_members which can be used to create hashers for types made from hashable data members and member functions which return a hashable value.
struct udt { int i{}; double fd(); };
template <>
struct std::hash<udl> : tprt::hash_members<udt, &udt::i, &udt::fd>{};
The library also provides utility hashers for types whose components are also hashable such as hash_chrono, hash_pair, hash_range, and hash_tuple.
This is a hobby project made to explore the latest C++ standards and compilers. As a result there is no minimum standard or compiler than this project will support. The project currently makes use of C++ 23 features.
The project uses cmake 3.28 as a build system.
- FNV compile time hash algorithms.
- Normalising unique object representations to hashable byte ranges.
- Compile time testing.
- Uses function objects to pass overload sets and function templates to higher order functions.
The project has been successfully compiled and tested with the following compilers on Kubuntu 24.04 LTS.
- git clone https://github.com/ThomasThorpe/tprt-hash-utils
- cd tprt-hash-utils && mkdir build && cd build
- cmake -DCMAKE_BUILD_TYPE=Release -G "Ninja" ..
- cmake --build . && ctest
- sudo cmake --install .